Functions
getInitialProps: Legacy Pages data loading
Legacy Pages data-loading API. Initial render runs on the server, but later client-side navigation can invoke it in the browser. A custom App has additional server-side behavior when navigating to a getServerSideProps page. Never use secrets or server-only database modules in a function that may run in the browser. Prefer modern per-page data methods for Pages Router and plan App Router migration separately. Source: https://nextjs.org/docs/pages/api-reference/functions/get-initial-props. Documentation-reviewed illustrative draft; installed declarations and runtime not verified.
Formal Syntax & Structure
nextjs syntaxnextjs
Page.getInitialProps = async (context) => ({...})Working Example
Example Snippetnextjs
import type { NextPage } from 'next';const Page: NextPage<{ title: string }> = ({ title }) => <h1>{title}</h1>;Page.getInitialProps = async () => ({ title: 'River Books' });export default Page;