Skip to content

Instantly share code, notes, and snippets.

@gothedistance
Created June 10, 2022 06:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gothedistance/b9703782e786094573b9b459b703f0b8 to your computer and use it in GitHub Desktop.
Save gothedistance/b9703782e786094573b9b459b703f0b8 to your computer and use it in GitHub Desktop.
Next.js Tutorial GetStaticProps by TypeScript Sample
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