Created
June 10, 2022 06:14
-
-
Save gothedistance/b9703782e786094573b9b459b703f0b8 to your computer and use it in GitHub Desktop.
Next.js Tutorial GetStaticProps by TypeScript Sample
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 { GetStaticProps, NextPage } from "next"; | |
type Post = { | |
id: string; | |
title: string; | |
}; | |
type Props = { posts: Post[]} | |
const Posts : NextPage<Props> = ( props ) => { | |
return <> | |
<ul> | |
{props.posts.map((post => | |
<li>{post.title}</li>) | |
)} | |
</ul> | |
</> | |
} | |
async function getPosts(): Promise<Post[]> { | |
return [ | |
{ id: '001', title: 'Title-1' }, | |
{ id: '002', title: 'Title-2' }, | |
{ id: '003', title: 'Title-3' } | |
]; | |
} | |
export const getStaticProps: GetStaticProps<Props> = async () => { | |
const posts = await getPosts(); | |
return { | |
props: { | |
posts, | |
}, | |
revalidate: 1 | |
}; | |
}; | |
export default Posts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment