Note: User detail page can be refreshed every 60 seconds. Instant update is not important.
export async function getStaticPaths() {
const res = await fetch('https://.../posts')
const posts = await res.json()
const paths = posts.map((post) => ({
params: { id: post.id },
}))
return { paths }
}
export async function getStaticProps({ params }) {
const res = await fetch(`https://.../posts/${params.id}`)
const post = await res.json()
return { props: { post } }
}
No . getStaticPaths is useful when it comes to statically generating lot's of pages incrementally .
Yes in next js you can use revalidate cache strategy only when you are generating static pages with getStaticProps like this :
export async function getStaticProps({ params }) {
const res = await fetch(`https://.../posts/${params.id}`);
const post = await res.json();
// revalidate value is basically in seconds so here it will revalidate the
// data every 1 second only If there is an update to it .
return { props: { post } , revalidate : 1 }
}