Skip to content

Instantly share code, notes, and snippets.

@angeloashmore
Last active September 1, 2022 20: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 angeloashmore/0fe94f70bdb593b5338889db7eff5398 to your computer and use it in GitHub Desktop.
Save angeloashmore/0fe94f70bdb593b5338889db7eff5398 to your computer and use it in GitHub Desktop.
An example Next.js page file written in TypeScript.
// 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