import { useState, useEffect } from "react";
function GoodsList(props) {
const [products, setProducts] = useState(null);
const goods = props.goods;
let productCards = [];
fetch('products.json').then(async response => {
setProducts(await response.json());
})
let content;
useEffect(() => {
if (products != null) {
for (let x = 0; x < products[goods].length; x++) {
productCards.push(
<div className="productCard" key={x}>
<div className="productPicture">
<img src={products[goods[x].pic]} /></div>
<div className="productName">{products[goods[x].name]}</div>
</div>
)
}
content = (
<div className="list">
{productCards}
</div>
);
console.log(productCards);
}
}
)
return content;
}
Initially I put the return of the JSX inside the useEffect function, but it was causing an error. Now it just doesn't return anything without any errors in the console, but the console.log inside useeffect outputs indefinitely somehow.