Last active
September 1, 2022 20:14
-
-
Save angeloashmore/0fe94f70bdb593b5338889db7eff5398 to your computer and use it in GitHub Desktop.
An example Next.js page file written in 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
// src/pages/index.tsx | |
import type { InferGetStaticPropsType, GetStaticPropsContext } from 'next' | |
// PageProps is typed using the inferred return type from `getStaticProps()`. | |
type PageProps = InferGetStaticPropsType<typeof getStaticProps> | |
export default function Page({ fetchedData }: PageProps) { | |
// `fetchedData` is typed as the return value of `client.someAPI()`. | |
} | |
export async function getStaticProps({ previewData }: GetStaticPropsContext) { | |
const fetchedData = await someAPICall() | |
return { | |
props: { | |
fetchedData, | |
}, | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment