Skip to content

Instantly share code, notes, and snippets.

@ibelick
Created February 15, 2022 14:11
Show Gist options
  • Save ibelick/3a952c74e29188f01991b3071f638389 to your computer and use it in GitHub Desktop.
Save ibelick/3a952c74e29188f01991b3071f638389 to your computer and use it in GitHub Desktop.
Next.js basic GetStaticProps with TypeScript
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