How to detect environment getInitialProps is running in #10761
Replies: 3 comments 1 reply
-
Hi - I realize this question might not get an answer, but wondering if I phrased it wrong or am not 'getting' something about nextjs. This static method appears key to how the entire framework works and yet the documentation around how it works and when/where it runs is sparse- possibly exacerbated by my deploying on zeit which appears to be running server-size even when i think i've done a 'static export.' All of which is to say, I'm confused here, and perhaps I'm overcomplicating it, but if there is something I can do to improve on this question i'd appreciate it. |
Beta Was this translation helpful? Give feedback.
-
If |
Beta Was this translation helpful? Give feedback.
-
MyPage.getInitialProps = ({buildEnv, query}) => {
switch (buildEnv) {
case 'STATIC_EXPORT`:
return fetchStaticExportProps(query)
case 'SERVER':
case 'BROWSER':
return fetchPropsTheOtherWay(query)
}
} My sense is that folks don't need something like this because you don't build for both situations, but I find the types of checks I wrote above while simply trying to understand it extremely counterintuitive. |
Beta Was this translation helpful? Give feedback.
-
I'm trying to understand how
getInitialProps
runs in different environments: On the client and server, as well as during static export. It seems you can only infer these states from other things about thegetInitialProps
context argument. I realize that #9524 will change some of this, but want to understand this piece of the api as well as possible. Is this pretty close?Beta Was this translation helpful? Give feedback.
All reactions