Still learning, and I have an issue understanding how I can get the data from an async function then show it in the DOM.
Indeed, I'm getting undefined, since the dom renders before the async function.
I'm stuck and my question is how to manage this situation ? What's the good practice ?
export default function ProductCard ({ product }) {
const { handle, title } = product.node
const [productDetails, setProductDetails] = useState();
const data = async () => {
const data = await getProduct(handle)
//console.log(data)
setProductDetails(data);
}
useEffect(() => {
data();
}, [])
//or data();
console.log("productDetails", productDetails);
return (
<>
{productDetails.handle}
</>
)
}
Thanks for the help and support.