export async function getStaticProps(context) {...}
// page/index.js
import path from "path";
import fs from "fs/promises";
function HomePage(props) {
const { products } = props;
console.log(products);
return (
<ul>
{products.map((product) => (
<li key={product.id}>{product.title}</li>
))}
</ul>
);
}
export async function getStaticProps() {
const filePath = path.join(process.cwd(), "data", "dummy-backend.json");
const jsonData = await fs.readFile(filePath);
const data = JSON.parse(jsonData);
return {
props: {
products: data.products,
},
};
}
export default HomePage;