Question from the Next.js test

Load blog post data at build time for a static render.

Easy

In a Next.js application in Page Router, you have a getStaticProps function in a blog.js file in the pages directory. What is this function for in this context?

// pages/blog.js
export async function getStaticProps(){
  const posts= await fetchBlogPosts()
  return{
    props:{ posts },
  };
}

export default function Blog({ posts }){
  return(
   <div>
     {posts.map(post=><div key={post.id}>{post.title}</div>)}
   </div>
  );
}
Author: AnasStatus: PublishedQuestion passed 184 times
Edit
3
Community Evaluations
developer avatar
Leopold
23/04/2024
Notion de base, important!