Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor data fetching API docs #30615

Merged
merged 78 commits into from Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
0518026
Conflicts
molebox Dec 16, 2021
72f3e3a
Fixed titles
molebox Oct 12, 2021
72c8730
Missing route path
molebox Oct 12, 2021
bf62134
Data fetching route was missing
molebox Oct 12, 2021
a4f471f
Changed title of data fetching sidenav item
molebox Oct 12, 2021
363da60
inline codeblocks
molebox Oct 12, 2021
45192e1
Conflicts - rebase on canary continue
molebox Oct 29, 2021
16a6afc
Moved TS to top level of main pages
molebox Oct 29, 2021
f7f60e8
Pulled out ISR and SWR, added cards, fixed routes
molebox Nov 2, 2021
9137669
Pulled out ISR and SWR, added cards, fixed routes
molebox Nov 2, 2021
02f6e4d
Removed redirect, moved to next-site
molebox Nov 12, 2021
7579859
conflicts
molebox Nov 12, 2021
4c48348
merge conflicts
molebox Nov 12, 2021
268d972
Removed duplicate doc
molebox Nov 12, 2021
7eebcd7
Silly merge left overs
molebox Nov 12, 2021
cea5cea
Update docs/api-reference/data-fetching/getInitialProps.md
molebox Nov 16, 2021
a01bcf6
Feedback changes, fleshout swr page, changed name, fixed links
molebox Nov 16, 2021
3034fc3
Added ISR not on build time. Clean up
molebox Nov 18, 2021
2511cdf
Moved some information to gsp
molebox Nov 22, 2021
a35b3c0
Update docs/api-reference/data-fetching/getServerSideProps.md
molebox Nov 30, 2021
2d7ce63
Update docs/api-reference/data-fetching/getServerSideProps.md
molebox Nov 30, 2021
3ef0509
Update docs/api-reference/data-fetching/getServerSideProps.md
molebox Nov 30, 2021
2e0ab34
Update docs/api-reference/data-fetching/getStaticPaths.md
molebox Nov 30, 2021
ce2699b
Update docs/api-reference/data-fetching/getStaticProps.md
molebox Nov 30, 2021
8203360
Update docs/api-reference/data-fetching/getStaticPaths.md
molebox Nov 30, 2021
5b48c16
Update docs/api-reference/data-fetching/getStaticPaths.md
molebox Nov 30, 2021
2ef9174
Update docs/api-reference/data-fetching/getStaticPaths.md
molebox Nov 30, 2021
77f2e74
Update docs/api-reference/data-fetching/getStaticProps.md
molebox Nov 30, 2021
b0adf8d
Update docs/api-reference/data-fetching/getStaticPaths.md
molebox Nov 30, 2021
d24d1a7
Update docs/api-reference/data-fetching/getStaticPaths.md
molebox Nov 30, 2021
b5c77cd
Update docs/api-reference/data-fetching/getStaticPaths.md
molebox Nov 30, 2021
e23b1ae
Update docs/api-reference/data-fetching/getStaticPaths.md
molebox Nov 30, 2021
b191d3f
Update docs/api-reference/data-fetching/getStaticProps.md
molebox Nov 30, 2021
de68ebe
Update docs/api-reference/data-fetching/getStaticProps.md
molebox Nov 30, 2021
cebe6ec
Conflicts part 2
molebox Dec 16, 2021
8ef0b0a
Update docs/basic-features/data-fetching/getStaticPaths.md
molebox Nov 30, 2021
2577778
Update docs/basic-features/data-fetching/index.md
molebox Dec 10, 2021
3d39200
Update docs/basic-features/data-fetching/index.md
molebox Dec 10, 2021
34f6561
Update docs/api-reference/data-fetching/getInitialProps.md
molebox Dec 10, 2021
38976b9
Update docs/api-reference/data-fetching/getServerSideProps.md
molebox Dec 10, 2021
a80eece
Update docs/api-reference/data-fetching/getStaticPaths.md
molebox Dec 10, 2021
2a339c3
Update docs/api-reference/data-fetching/getStaticPaths.md
molebox Dec 10, 2021
f6bc0e2
Update docs/api-reference/data-fetching/getServerSideProps.md
molebox Dec 10, 2021
8fac37d
Update docs/api-reference/data-fetching/getStaticProps.md
molebox Dec 10, 2021
c62565c
Update docs/basic-features/data-fetching/client-side.md
molebox Dec 10, 2021
c682442
Update docs/basic-features/data-fetching/client-side.md
molebox Dec 10, 2021
0606f5b
Update docs/basic-features/data-fetching/client-side.md
molebox Dec 10, 2021
cfe9d96
Update docs/basic-features/data-fetching/client-side.md
molebox Dec 10, 2021
14136a5
Update docs/basic-features/data-fetching/client-side.md
molebox Dec 10, 2021
58dce75
Update docs/basic-features/data-fetching/getServerSideProps.md
molebox Dec 10, 2021
da73eef
Update docs/basic-features/data-fetching/getServerSideProps.md
molebox Dec 10, 2021
b991731
Update docs/basic-features/data-fetching/getServerSideProps.md
molebox Dec 10, 2021
489f665
Update docs/basic-features/data-fetching/getStaticPaths.md
molebox Dec 10, 2021
16a5726
Update docs/basic-features/data-fetching/getStaticPaths.md
molebox Dec 10, 2021
edd14e7
Update docs/basic-features/data-fetching/getStaticProps.md
molebox Dec 10, 2021
988fe89
Update docs/basic-features/data-fetching/incremental-static-regenerat…
molebox Dec 10, 2021
394ae35
Update docs/basic-features/data-fetching/incremental-static-regenerat…
molebox Dec 10, 2021
77f70b9
Changed heading
molebox Nov 30, 2021
b493d11
Conflicts in getServerSideProps
molebox Dec 10, 2021
ac8da9d
Feedback changes
molebox Dec 10, 2021
7c75549
Fixed internal links to new pages
molebox Dec 10, 2021
ae0eff3
Conflicts + fix links
molebox Dec 10, 2021
e277eac
Fixed meta description rendering because of '
molebox Dec 10, 2021
c30c104
Added missing suggestions from feedback
molebox Dec 10, 2021
d141210
Removed comment that linked to removed section
molebox Dec 10, 2021
b257aa2
Fixed alex warnings
molebox Dec 14, 2021
2b1650f
Merge branch 'canary' into refactor-data-fetching
molebox Dec 20, 2021
ef2131c
Changed path of getInitialProps and getServerSideProps to kebab-case
molebox Dec 20, 2021
93ff219
Changed path of getStaticPaths to kebab-case
molebox Dec 20, 2021
ceea662
Chnaged path of getStaticProps to kebab-case
molebox Dec 20, 2021
b6a659b
Moved card linking client-side lower in the list
molebox Dec 20, 2021
7764ca1
Merge branch 'canary' into refactor-data-fetching
molebox Dec 20, 2021
2ce28b6
Merge branch 'canary' into refactor-data-fetching
molebox Dec 21, 2021
c256c7d
Merge branch 'canary' into refactor-data-fetching
molebox Dec 22, 2021
9c6057c
Merge branch 'canary' into refactor-data-fetching
molebox Jan 3, 2022
efb0afd
Merge branch 'canary' into refactor-data-fetching
molebox Jan 10, 2022
74eb014
Merge branch 'canary' into refactor-data-fetching
molebox Jan 11, 2022
c140ccf
Merge branch 'canary' into refactor-data-fetching
molebox Jan 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/advanced-features/automatic-static-optimization.md
Expand Up @@ -20,7 +20,7 @@ If the above is not the case, Next.js will **statically optimize** your page aut

During prerendering, the router's `query` object will be empty since we do not have `query` information to provide during this phase. After hydration, Next.js will trigger an update to your application to provide the route parameters in the `query` object.

> **Note:** Parameters added with [dynamic routes](/docs/routing/dynamic-routes.md) to a page that's using [`getStaticProps`](/docs/basic-features/data-fetching.md#getstaticprops-static-generation) will always be available inside the `query` object.
> **Note:** Parameters added with [dynamic routes](/docs/routing/dynamic-routes.md) to a page that's using [`getStaticProps`](/docs/basic-features/data-fetching/get-static-props.md) will always be available inside the `query` object.

`next build` will emit `.html` files for statically optimized pages. For example, the result for the page `pages/about.js` would be:

Expand All @@ -36,5 +36,5 @@ And if you add `getServerSideProps` to the page, it will then be JavaScript, lik

## Caveats

- If you have a [custom `App`](/docs/advanced-features/custom-app.md) with `getInitialProps` then this optimization will be turned off in pages without [Static Generation](/docs/basic-features/data-fetching.md#getstaticprops-static-generation).
- If you have a [custom `App`](/docs/advanced-features/custom-app.md) with `getInitialProps` then this optimization will be turned off in pages without [Static Generation](/docs/basic-features/data-fetching/get-static-props.md).
- If you have a [custom `Document`](/docs/advanced-features/custom-document.md) with `getInitialProps` be sure you check if `ctx.req` is defined before assuming the page is server-side rendered. `ctx.req` will be `undefined` for pages that are prerendered.
6 changes: 3 additions & 3 deletions docs/advanced-features/custom-app.md
Expand Up @@ -38,14 +38,14 @@ export default MyApp

The `Component` prop is the active `page`, so whenever you navigate between routes, `Component` will change to the new `page`. Therefore, any props you send to `Component` will be received by the `page`.

`pageProps` is an object with the initial props that were preloaded for your page by one of our [data fetching methods](/docs/basic-features/data-fetching.md), otherwise it's an empty object.
`pageProps` is an object with the initial props that were preloaded for your page by one of our [data fetching methods](/docs/basic-features/data-fetching/index.md), otherwise it's an empty object.

### Caveats

- If your app is running and you added a custom `App`, you'll need to restart the development server. Only required if `pages/_app.js` didn't exist before.
- Adding a custom [`getInitialProps`](/docs/api-reference/data-fetching/getInitialProps.md) in your `App` will disable [Automatic Static Optimization](/docs/advanced-features/automatic-static-optimization.md) in pages without [Static Generation](/docs/basic-features/data-fetching.md#getstaticprops-static-generation).
- Adding a custom [`getInitialProps`](/docs/api-reference/data-fetching/get-initial-props.md) in your `App` will disable [Automatic Static Optimization](/docs/advanced-features/automatic-static-optimization.md) in pages without [Static Generation](/docs/basic-features/data-fetching/get-static-props.md).
- When you add `getInitialProps` in your custom app, you must `import App from "next/app"`, call `App.getInitialProps(appContext)` inside `getInitialProps` and merge the returned object into the return value.
- `App` currently does not support Next.js [Data Fetching methods](/docs/basic-features/data-fetching.md) like [`getStaticProps`](/docs/basic-features/data-fetching.md#getstaticprops-static-generation) or [`getServerSideProps`](/docs/basic-features/data-fetching.md#getserversideprops-server-side-rendering).
- `App` currently does not support Next.js [Data Fetching methods](/docs/basic-features/data-fetching/index.md) like [`getStaticProps`](/docs/basic-features/data-fetching/get-static-props.md) or [`getServerSideProps`](/docs/basic-features/data-fetching/get-server-side-props.md).

### TypeScript

Expand Down
4 changes: 2 additions & 2 deletions docs/advanced-features/custom-document.md
Expand Up @@ -45,7 +45,7 @@ Custom attributes are allowed as props, like `lang`:

The `<Head />` component used here is not the same one from [`next/head`](/docs/api-reference/next/head.md). The `<Head />` component used here should only be used for any `<head>` code that is common for all pages. For all other cases, such as `<title>` tags, we recommend using [`next/head`](/docs/api-reference/next/head.md) in your pages or components.

The `ctx` object is equivalent to the one received in [`getInitialProps`](/docs/api-reference/data-fetching/getInitialProps.md#context-object), with one addition:
The `ctx` object is equivalent to the one received in [`getInitialProps`](/docs/api-reference/data-fetching/get-initial-props.md#context-object), with one addition:

- `renderPage`: `Function` - a callback that runs the actual React rendering logic (synchronously). It's useful to decorate this function in order to support server-rendering wrappers like Aphrodite's [`renderStatic`](https://github.com/Khan/aphrodite#server-side-rendering)

Expand All @@ -54,7 +54,7 @@ The `ctx` object is equivalent to the one received in [`getInitialProps`](/docs/
- `Document` is only rendered in the server, event handlers like `onClick` won't work.
- React components outside of `<Main />` will not be initialized by the browser. Do _not_ add application logic here or custom CSS (like `styled-jsx`). If you need shared components in all your pages (like a menu or a toolbar), take a look at the [`App`](/docs/advanced-features/custom-app.md) component instead.
- `Document`'s `getInitialProps` function is not called during client-side transitions, nor when a page is [statically optimized](/docs/advanced-features/automatic-static-optimization.md).
- `Document` currently does not support Next.js [Data Fetching methods](/docs/basic-features/data-fetching.md) like [`getStaticProps`](/docs/basic-features/data-fetching.md#getstaticprops-static-generation) or [`getServerSideProps`](/docs/basic-features/data-fetching.md#getserversideprops-server-side-rendering).
- `Document` currently does not support Next.js [Data Fetching methods](/docs/basic-features/data-fetching/index.md) like [`getStaticProps`](/docs/basic-features/data-fetching/get-static-props.md) or [`getServerSideProps`](/docs/basic-features/data-fetching/get-server-side-props.md).

## Customizing `renderPage`

Expand Down
4 changes: 2 additions & 2 deletions docs/advanced-features/custom-error-page.md
Expand Up @@ -21,7 +21,7 @@ export default function Custom404() {
}
```

> **Note**: You can use [`getStaticProps`](/docs/basic-features/data-fetching.md#getstaticprops-static-generation) inside this page if you need to fetch data at build time.
> **Note**: You can use [`getStaticProps`](/docs/basic-features/data-fetching/get-static-props.md) inside this page if you need to fetch data at build time.

## 500 Page

Expand All @@ -38,7 +38,7 @@ export default function Custom500() {
}
```

> **Note**: You can use [`getStaticProps`](/docs/basic-features/data-fetching.md#getstaticprops-static-generation) inside this page if you need to fetch data at build time.
> **Note**: You can use [`getStaticProps`](/docs/basic-features/data-fetching/get-static-props.md) inside this page if you need to fetch data at build time.

### More Advanced Error Page Customizing

Expand Down
4 changes: 2 additions & 2 deletions docs/advanced-features/i18n-routing.md
Expand Up @@ -207,7 +207,7 @@ You can access the locale information via the Next.js router. For example, using
- `locales` contains all configured locales.
- `defaultLocale` contains the configured default locale.

When [pre-rendering](/docs/basic-features/pages.md#static-generation-recommended) pages with `getStaticProps` or `getServerSideProps`, the locale information is provided in [the context](/docs/basic-features/data-fetching.md#getstaticprops-static-generation) provided to the function.
When [pre-rendering](/docs/basic-features/pages.md#static-generation-recommended) pages with `getStaticProps` or `getServerSideProps`, the locale information is provided in [the context](/docs/basic-features/data-fetching/get-static-props.md) provided to the function.

When leveraging `getStaticPaths`, the configured locales are provided in the context parameter of the function under `locales` and the configured defaultLocale under `defaultLocale`.

Expand Down Expand Up @@ -293,7 +293,7 @@ Next.js doesn't know about variants of a page so it's up to you to add the `href

### Dynamic Routes and `getStaticProps` Pages

For pages using `getStaticProps` with [Dynamic Routes](/docs/routing/dynamic-routes.md), all locale variants of the page desired to be prerendered need to be returned from [`getStaticPaths`](/docs/basic-features/data-fetching.md#getstaticpaths-static-generation). Along with the `params` object returned for `paths`, you can also return a `locale` field specifying which locale you want to render. For example:
For pages using `getStaticProps` with [Dynamic Routes](/docs/routing/dynamic-routes.md), all locale variants of the page desired to be prerendered need to be returned from [`getStaticPaths`](/docs/basic-features/data-fetching/get-static-paths.md). Along with the `params` object returned for `paths`, you can also return a `locale` field specifying which locale you want to render. For example:

```js
// pages/blog/[slug].js
Expand Down
4 changes: 2 additions & 2 deletions docs/advanced-features/preview-mode.md
Expand Up @@ -27,7 +27,7 @@ description: Next.js has the preview mode for statically generated pages. You ca
</ul>
</details>

In the [Pages documentation](/docs/basic-features/pages.md) and the [Data Fetching documentation](/docs/basic-features/data-fetching.md), we talked about how to pre-render a page at build time (**Static Generation**) using `getStaticProps` and `getStaticPaths`.
In the [Pages documentation](/docs/basic-features/pages.md) and the [Data Fetching documentation](/docs/basic-features/data-fetching/index.md), we talked about how to pre-render a page at build time (**Static Generation**) using `getStaticProps` and `getStaticPaths`.

Static Generation is useful when your pages fetch data from a headless CMS. However, it’s not ideal when you’re writing a draft on your headless CMS and want to **preview** the draft immediately on your page. You’d want Next.js to render these pages at **request time** instead of build time and fetch the draft content instead of the published content. You’d want Next.js to bypass Static Generation only for this specific case.

Expand Down Expand Up @@ -230,7 +230,7 @@ This ensures that the bypass cookie can’t be guessed.
The following pages might also be useful.

<div class="card">
<a href="/docs/basic-features/data-fetching.md">
<a href="/docs/basic-features/data-fetching/index.md">
<b>Data Fetching:</b>
<small>Learn more about data fetching in Next.js.</small>
</a>
Expand Down
20 changes: 10 additions & 10 deletions docs/advanced-features/static-html-export.md
Expand Up @@ -13,7 +13,7 @@ description: Export your Next.js app to static HTML, and run it standalone witho

`next export` allows you to export your Next.js application to static HTML, which can be run standalone without the need of a Node.js server. It is recommended to only use `next export` if you don't need any of the [unsupported features](#unsupported-features) requiring a server.

If you're looking to build a hybrid site where only _some_ pages are prerendered to static HTML, Next.js already does that automatically. Learn more about [Automatic Static Optimization](/docs/advanced-features/automatic-static-optimization.md) and [Incremental Static Regeneration](/docs/basic-features/data-fetching.md#incremental-static-regeneration).
If you're looking to build a hybrid site where only _some_ pages are prerendered to static HTML, Next.js already does that automatically. Learn more about [Automatic Static Optimization](/docs/advanced-features/automatic-static-optimization.md) and [Incremental Static Regeneration](/docs/basic-features/data-fetching/incremental-static-regeneration.md).

## `next export`

Expand All @@ -27,7 +27,7 @@ Update your build script in `package.json` to use `next export`:

Running `npm run build` will generate an `out` directory.

`next export` builds an HTML version of your app. During `next build`, [`getStaticProps`](/docs/basic-features/data-fetching.md#getstaticprops-static-generation) and [`getStaticPaths`](/docs/basic-features/data-fetching.md#getstaticpaths-static-generation) will generate an HTML file for each page in your `pages` directory (or more for [dynamic routes](/docs/routing/dynamic-routes.md). Then, `next export` will copy the already exported files into the correct directory. `getInitialProps` will generate the HTML files during `next export` instead of `next build`.
`next export` builds an HTML version of your app. During `next build`, [`getStaticProps`](/docs/basic-features/data-fetching/get-static-props.md) and [`getStaticPaths`](/docs/basic-features/data-fetching/get-static-paths.md) will generate an HTML file for each page in your `pages` directory (or more for [dynamic routes](/docs/routing/dynamic-routes.md). Then, `next export` will copy the already exported files into the correct directory. `getInitialProps` will generate the HTML files during `next export` instead of `next build`.

For more advanced scenarios, you can define a parameter called [`exportPathMap`](/docs/api-reference/next.config.js/exportPathMap.md) in your [`next.config.js`](/docs/api-reference/next.config.js/introduction.md) file to configure exactly which pages will be generated.

Expand All @@ -40,9 +40,9 @@ The majority of core Next.js features needed to build a static site are supporte
- Preloading JavaScript
- [Dynamic Imports](/docs/advanced-features/dynamic-import.md)
- Any styling options (e.g. CSS Modules, styled-jsx)
- [Client-side data fetching](/docs/basic-features/data-fetching.md#fetching-data-on-the-client-side)
- [`getStaticProps`](/docs/basic-features/data-fetching.md#getstaticprops-static-generation)
- [`getStaticPaths`](/docs/basic-features/data-fetching.md#getstaticpaths-static-generation)
- [Client-side data fetching](/docs/basic-features/data-fetching/client-side.md)
- [`getStaticProps`](/docs/basic-features/data-fetching/get-static-props.md)
- [`getStaticPaths`](/docs/basic-features/data-fetching/get-static-paths.md)
- [Image Optimization](/docs/basic-features/image-optimization.md) using a [custom loader](/docs/basic-features/image-optimization.md#loader)

## Unsupported Features
Expand All @@ -56,16 +56,16 @@ Features that require a Node.js server, or dynamic logic that cannot be computed
- [Redirects](/docs/api-reference/next.config.js/redirects.md)
- [Headers](/docs/api-reference/next.config.js/headers.md)
- [Middleware](/docs/middleware.md)
- [Incremental Static Regeneration](/docs/basic-features/data-fetching.md#incremental-static-regeneration)
- [`fallback: true`](/docs/basic-features/data-fetching.md#fallback-true)
- [`getServerSideProps`](/docs/basic-features/data-fetching.md#getserversideprops-server-side-rendering)
- [Incremental Static Regeneration](/docs/basic-features/data-fetching/incremental-static-regeneration.md)
- [`fallback: true`](/docs/api-reference/data-fetching/get-static-paths.md#fallback-true)
- [`getServerSideProps`](/docs/basic-features/data-fetching/get-server-side-props.md)

### `getInitialProps`

It's possible to use the [`getInitialProps`](/docs/api-reference/data-fetching/getInitialProps.md) API instead of `getStaticProps`, but it comes with a few caveats:
It's possible to use the [`getInitialProps`](/docs/api-reference/data-fetching/get-initial-props.md) API instead of `getStaticProps`, but it comes with a few caveats:

- `getInitialProps` cannot be used alongside `getStaticProps` or `getStaticPaths` on any given page. If you have dynamic routes, instead of using `getStaticPaths` you'll need to configure the [`exportPathMap`](/docs/api-reference/next.config.js/exportPathMap.md) parameter in your [`next.config.js`](/docs/api-reference/next.config.js/introduction.md) file to let the exporter know which HTML files it should output.
- When `getInitialProps` is called during export, the `req` and `res` fields of its [`context`](/docs/api-reference/data-fetching/getInitialProps.md#context-object) parameter will be empty objects, since during export there is no server running.
- When `getInitialProps` is called during export, the `req` and `res` fields of its [`context`](/docs/api-reference/data-fetching/get-initial-props.md#context-object) parameter will be empty objects, since during export there is no server running.
- `getInitialProps` **will be called on every client-side navigation**, if you'd like to only fetch data at build-time, switch to `getStaticProps`.
- `getInitialProps` should fetch from an API and cannot use Node.js-specific libraries or the file system like `getStaticProps` can.

Expand Down
Expand Up @@ -4,15 +4,11 @@ description: Enable Server-Side Rendering in a page and do initial data populati

# getInitialProps

> **Recommended: [`getStaticProps`](/docs/basic-features/data-fetching.md#getstaticprops-static-generation) or [`getServerSideProps`](/docs/basic-features/data-fetching.md#getserversideprops-server-side-rendering)**.
>
> If you're using Next.js 9.3 or newer, we recommend that you use `getStaticProps` or `getServerSideProps` instead of `getInitialProps`.
>
> These new data fetching methods allow you to have a granular choice between static generation and server-side rendering. Learn more on the documentation for [Pages](/docs/basic-features/pages.md) and [Data Fetching](/docs/basic-features/data-fetching.md).
**Recommended: [`getStaticProps`](/docs/basic-features/data-fetching/get-static-props.md) or [`getServerSideProps`](/docs/basic-features/data-fetching/get-server-side-props.md)** instead of `getInitialProps`. These data fetching methods allow you to have a granular choice between static generation and server-side rendering.

`getInitialProps` enables [server-side rendering](/docs/basic-features/pages.md#server-side-rendering) in a page and allows you to do **initial data population**, it means sending the [page](/docs/basic-features/pages.md) with the data already populated from the server. This is especially useful for [SEO](https://en.wikipedia.org/wiki/Search_engine_optimization).

> `getInitialProps` will disable [Automatic Static Optimization](/docs/advanced-features/automatic-static-optimization.md).
`getInitialProps` will disable [Automatic Static Optimization](/docs/advanced-features/automatic-static-optimization.md).

`getInitialProps` is an [`async`](https://vercel.com/blog/async-and-await) function that can be added to any page as a [`static method`](https://javascript.info/static-properties-methods). Take a look at the following example:

Expand Down Expand Up @@ -123,22 +119,8 @@ export default class Page extends React.Component<Props> {
For more information on what to do next, we recommend the following sections:

<div class="card">
<a href="/docs/basic-features/data-fetching.md">
<a href="/docs/basic-features/data-fetching/index.md">
<b>Data Fetching:</b>
<small>Learn more about data fetching in Next.js.</small>
</a>
</div>

<div class="card">
<a href="/docs/basic-features/pages.md">
<b>Pages:</b>
<small>Learn more about what pages are in Next.js.</small>
</a>
</div>

<div class="card">
<a href="/docs/advanced-features/automatic-static-optimization.md">
<b>Automatic Static Optimization:</b>
<small>Learn about how Next.js automatically optimizes your pages.</small>
</a>
</div>