Answers for "getstaticpaths errors after new posts"

0

getstaticpaths errors after new posts

You can also use getStaticPaths with fallback to true.
And getStaticProps with revalidate whicth triggers incremental builds basiclly.
to avoid error after build
export async function getStaticPaths() {
  const res = await fetch(`${baseUrl}/wp-json/wp/v2/posts`)
  const posts = await res.json()
  const paths = posts.map(({ slug }) => ({ params: { slug: `${slug}` } }))
  return {
    paths,
    fallback: true,
  }
}

export async function getStaticProps(context) {
  const resPost = await fetch(`${baseUrl}/wp-json/wp/v2/posts?slug=${context.params.slug}`)

  const post = await resPost.json()

  return {
    props: {
      post,
    },
    revalidate: 10,
  }
}
Posted by: Guest on February-07-2022

Code answers related to "TypeScript"

Browse Popular Code Answers by Language