Currently getInitialProps runs once on the server and once on the client. Is there a way to disable it from running on the client or preserving the props it got from the server render on certain pages?
To make it clear, getInitialProps runs on server if it's server rendering, and does on client if page transition occurs by using Link component or props.url.push().
If you don't want to provide props on client for example, you can write like the following.
const isServer = typeof window === 'undefined'
static getInitialProps () {
if (isServer) {
return { value: 'hi' }
} else {
return {}
}
}
For some reason getInitialProps is running on the client as soon as it mounts. Maybe it's because I'm using next's programmatic API. I'll be looking into it to see if it's a problem on my end.
Most helpful comment
To make it clear,
getInitialPropsruns on server if it's server rendering, and does on client if page transition occurs by usingLinkcomponent orprops.url.push().If you don't want to provide props on client for example, you can write like the following.