Skip to content

Instantly share code, notes, and snippets.

@bengrunfeld
Created July 22, 2020 08:37
Show Gist options
  • Save bengrunfeld/08ac34f6cf76ea70478c14057f148348 to your computer and use it in GitHub Desktop.
Save bengrunfeld/08ac34f6cf76ea70478c14057f148348 to your computer and use it in GitHub Desktop.
import { useRouter } from 'next/router'
const Post = ({ post }) => {
const router = useRouter()
if (router.isFallback) {
return <div>Loading...</div>
}
return (
<div>{...post}</div>
)
}
export async function getStaticPaths() {
return {
paths: [{ params: { id: '1' } }, { params: { id: '2' } }],
fallback: true,
}
}
export async function getStaticProps({ params }) {
// if url was /posts/3, params.id will be 3
const res = await fetch(`https://.../${params.id}`)
const post = await res.json()
return { props: { post } }
}
export default Post
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment