Skip to content

How / when / why use getStaticProps #17165

Answered by leerob
Devalo asked this question in Help
Discussion options

You must be logged in to vote

Does that mean I have to set up a cron job or something else,
which restarts the server when the client is adding or editing content?

Nope! As you found out, using revalidate is the perfect solution for your problem. For example:

export async function getStaticProps({ params }) {
  // params contains the post `id`.
  // If the route is like /posts/1, then is 1
  const res = await fetch(`https://.../posts/${}`)
  const post = await res.json()

  // Pass post data to the page via props
  return {
    props: { post },
    // Re-generate the post at most once per second
    // if a request comes in
    revalidate: 1,

You can change the revalidate value depending on …

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by leerob
Comment options

You must be logged in to vote
1 reply
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants