Unverified Commit 3075c3ff authored by Daniel Cavanagh's avatar Daniel Cavanagh Committed by GitHub

Note about manually passing props from custom app (#37329)

I've wasted a couple of hours trying to work out why my static build wasn't passing through the props automatically as the docs say it should

Turns out it's the default app doing that and a custom app has to manually passed the props through

It wasn't obvious to me to look in the custom app doc where it's mentioned, so I've added a small note to the `getStaticProps` doc about this that points to the custom app doc
Co-authored-by: 's avatarJJ Kasper <22380829+ijjk@users.noreply.github.com>
parent 1c1fbeb4
...@@ -126,12 +126,14 @@ When using Incremental Static Generation, `getStaticProps` will be executed in t ...@@ -126,12 +126,14 @@ When using Incremental Static Generation, `getStaticProps` will be executed in t
## Where can I use getStaticProps ## Where can I use getStaticProps
`getStaticProps` can only be exported from a **page**. You **cannot** export it from non-page files. `getStaticProps` can only be exported from a **page**. You **cannot** export it from non-page files, `_app`, `_document`, or `_error`.
One of the reasons for this restriction is that React needs to have all the required data before the page is rendered. One of the reasons for this restriction is that React needs to have all the required data before the page is rendered.
Also, you must use export `getStaticProps` as a standalone function — it will **not** work if you add `getStaticProps` as a property of the page component. Also, you must use export `getStaticProps` as a standalone function — it will **not** work if you add `getStaticProps` as a property of the page component.
> Note: if you have created a [custom app](/docs/advanced-features/custom-app.md), ensure you are passing the `pageProps` to the page component as shown in the linked document, otherwise the props will be empty.
## Runs on every request in development ## Runs on every request in development
In development (`next dev`), `getStaticProps` will be called on every request. In development (`next dev`), `getStaticProps` will be called on every request.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment