I'm trying to use a fake api found at https://fakestoreapi.com/ to get data into my Next js app. But I keep getting an undefined reference error, even though I got the code snippet from the official next js docs. This is my code
import { Box, Heading } from "@chakra-ui/react";
export async function getStaticProps() {
const response = await fetch("https://fakestoreapi.com/products");
const data = await response.json();
return {
props: {
products,
},
};
}
function ProductList() {
return (
<Box>
{products.map((product) => (
<Box>
<Text> {product.title} </Text>
</Box>
))}
</Box>
);
}
export default ProductList;
And this is the error I keep getting
ReferenceError: products is not defined