Atila
I'm on a mission to make code simple. When not recording screencasts or courses, you may find me either writing and talking about jamstack, performance, or developer tooling.
props during build time
paths for dynamic routes
props for each request
makes one fetch request to retrieve `props`
returns the necessary `props` so the page re-renders
generates a JSON with the result for client-side navigation
when provided, page will rebuild without needing to deploy everything again
page components for non-predefined paths
e.g.: `[slug].tsx`
false: unmatched route returns `404`
blocking: will SSR unmatched paths on-demand
true: serves fallback version for unmatched paths
export const Post = ({ title, content }) => (
<main>
<h1>{post.title}</h1>
<article>{content}</article>
</main>
)
export async function getStaticProps(context) {
const res = await getPost('post-slug')
const { title, content } = await res.json()
return {
props: {
title,
content
},
}
}
export const Post = ({ title, content }) => (
<main>
<h1>{post.title}</h1>
<article>{content}</article>
</main>
)
export async function getStaticProps(context) {
const res = await getPost('post-slug')
const { title, content } = await res.json()
return {
props: {
title,
content
},
revalidate: 6 * 60 // time in seconds
}
}
export const Post = ({ title, content }) => (
<main>
<h1>{post.title}</h1>
<article>{content}</article>
</main>
)
export async function getServerSideProps(context) {
const res = await getPost('post-slug')
const { title, content } = await res.json()
return {
props: {
title,
content
},
}
}
export async function getStaticProps(context) {
const res = await getPostInfo(context.params.id)
const { title, content } = await res.json()
return {
props: {
title,
content
},
}
}
export async function getStaticPaths() {
const postPaths = await getAllPostsFromDir(path.join(process.cwd, 'posts'))
return {
paths: postPaths,
fallback: false
}
}
By Atila