index.js file
export default function Home({ posts }) {
return (
<div>
{posts &&
posts.map((post) => (
<div key={post.id}>
<h2>{post.Title}</h2>
</div>
))}
</div>
);
}
export async function getStaticProps() {
const res = await fetch("http://localhost:1337/api/posts");
const posts = await res.json();
return {
props: { posts },
};
}
and this is the error that appears to me "TypeError: posts.map is not a function" Any idea about it?
console.log(posts)in yourgetStaticProps()function, can you confirm that it's an array?