I have to pass JSON data from Data.js to App.js. If I console.log data in Data.js everything is okay, however when I try to pass it for using in cards it shows me this Error.
App.js
import React from "react";
import { Card, Button, Container, Row } from "react-bootstrap";
import "./styles.css";
import Data from "./components/Data";
function createCard(item) {
return (
<Card style={{ width: "18rem" }}>
<Card.Img variant="top" src="" />
<Card.Body>
<Card.Title>{item.name}</Card.Title>
<Card.Text>Kod: {item.article} </Card.Text>
<Button variant="primary">{item.salePrices[0].value / 100}AZN</Button>
</Card.Body>
</Card>
);
}
export default function App() {
return (
<div className="App">
<Container>
<Row className="justify-content-md-center">{Data.map(createCard)}</Row>
</Container>
</div>
);
}
Data.js
import fetch from 'node-fetch';
var options = {
headers: {
'Authorization': 'Basic ' + loginPassword
}
};
(async () => {
const response = await fetch(url, options);
const data = await response.json();
})();
export default data;
P.S. Two moments which in my opinion can help to solve this problem.
First is when I try to console.log data outside of the async function it doesn't work, so that means I can reach the value only inside of that async function.
The second moment is when I add const test = "1"; to data.js and try to pass it export default test; to App.js it also shows the same error as I mentioned before.
Thanks in advance
