Created
February 15, 2022 14:11
-
-
Save ibelick/3a952c74e29188f01991b3071f638389 to your computer and use it in GitHub Desktop.
Next.js basic GetStaticProps with TypeScript
This file contains 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"; | |
interface Data { | |
title: string; | |
} | |
interface HomePageProps { | |
data: Data; | |
} | |
const Home: NextPage<HomePageProps> = (props) => { | |
return ( | |
<div> | |
<h1>{props.data.title}</h1> | |
</div> | |
); | |
}; | |
export const getStaticProps: GetStaticProps<HomePageProps> = async () => { | |
try { | |
const { data, errors } = await someQuery(); | |
if (errors || !data) { | |
return { notFound: true }; | |
} | |
return { props: { data } }; | |
} catch (err) { | |
return { notFound: true }; | |
} | |
}; | |
export default Home; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment