Created
July 22, 2020 08:37
-
-
Save bengrunfeld/08ac34f6cf76ea70478c14057f148348 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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