Build-time static generation
A Pages Router page has CMS data available before deployment and should be generated ahead of requests.
Next.js 16+ · Type Alias
GetStaticProps is the TypeScript type alias for a Pages Router function that supplies data for static page generation. It is a legacy Pages Router API; App Router applications use Server Components and App Router data-fetching APIs instead.
GetStaticProps is a Pages Router type alias for the function that supplies data to a statically generated page. It describes the context input and the result containing props or a redirect/not-found response, optionally with revalidation; App Router code instead fetches in Server Components.
type GetStaticProps<Props extends { [key: string]: any } = { [key: string]: any }, Params extends ParsedUrlQuery = ParsedUrlQuery, Preview extends PreviewData = PreviewData> = (context: GetStaticPropsContext<Params, Preview>) => Promise<GetStaticPropsResult<Props>>| Name | Type | Description |
|---|---|---|
context | GetStaticPropsContext | Context supplied by Next.js, including page-generation information such as params for dynamic Pages Router routes. |
GetStaticPropsResult<Props>: an object containing props, redirect, or notFound, optionally with revalidate.
import type { GetStaticProps, InferGetStaticPropsType } from 'next'
type Post = { id: string; title: string }
export const getStaticProps = (async () => {
const res = await fetch('https://example.com/api/posts')
const posts: Post[] = await res.json()
return { props: { posts }, revalidate: 60 }
}) satisfies GetStaticProps<{ posts: Post[] }>
export default function Page({ posts }: InferGetStaticPropsType<typeof getStaticProps>) {
return <main>{posts.map((post) => <h2 key={post.id}>{post.title}</h2>)}</main>
}A Pages Router page fetches build-time data, exposes it as typed props, and permits regeneration after 60 seconds.
A Pages Router page has CMS data available before deployment and should be generated ahead of requests.
A dynamic Pages Router page uses a generated path and needs typed route parameters while producing page props.
A generated page should refresh after a configured interval without rebuilding the entire site.
GetStaticProps is a TypeScript type alias that describes a Pages Router data function. The function runs during static generation and returns an object with props, redirect, or notFound, with optional revalidate.
Follow-up: How would this change in the App Router? Fetch data in Server Components and use the App Router's caching and revalidation APIs instead of exporting getStaticProps.
It is used with a page-level getStaticProps export to type its context and return value. The returned props become inputs to the page during prerendering.
Follow-up: How can the page component infer the returned prop shape? Use Next.js's InferGetStaticPropsType utility with typeof getStaticProps.
The return type permits props, redirect, or notFound, and can include revalidate. Revalidation allows a generated page to be regenerated after a specified interval.
Follow-up: What limitation remains even when revalidation is configured? The function still does not receive the incoming request, so request-specific data cannot drive generation.
GetStaticPropsContextGetStaticPropsResultInferGetStaticPropsTypegetStaticPropsgetStaticPathsgenerateStaticParamsServer Components