Skip to content

How does exactly getInitialProps works in the custom app #38067

Answered by icyJoseph
ramirezsandin asked this question in Help

You must be logged in to vote

getInitialProps is a bit wild, because, it may run, client side and server side.

When a user comes to your site, getInitialProps runs server side, after that, it runs on the client, for every SPA like page transition, unless the page it transitions to, runs getServerSideProps.

When you have getInitialProps in the _app file, you'll see this Warning:

Warning: You have opted-out of Automatic Static Optimisation due to `getInitialProps` in `pages/_app`. This does not opt-out pages with `getStaticProps`

Page Props

There's an often overlooked element in _app and that's what I am calling here, pageProps:

import type { AppProps } from "next/app";

function MyApp({ Component, pageProps }: AppProps) 

Replies: 1 comment 3 replies

You must be logged in to vote
3 replies
@ramirezsandin

@icyJoseph

@ramirezsandin

Answer selected by ramirezsandin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants