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 513 times
Edit
7
Community EvaluationsNo one has reviewed this question yet, be the first!