#Do not understand what getInitialProps does for color scheme in cookies (NextJS)

4 messages · Page 1 of 1 (latest)

sly orchid
#

Update: ```If you’re creating newer Next.js applications, there is probably no reason to use legacy methods like getInitialProps because getServerSideProps and getStaticProps provide better functionality and semantics.

In this article, we clarified the differences between getServerSideProps and getInitialProps, looking at an example of how we can solve context switching in getInitialProps with getServerSideProps.

I hope you enjoyed this article, and if you have any questions, please leave a comment. To learn more about Next.js and other meta frameworks, be sure to check out this article comparing Next.js and Remix.```

#

My question now is: is there any reason why the example uses getInitialProps? Or can I safely use getServerSideProps without fear

lofty flame
#
  • App does not support Next.js Data Fetching methods like getStaticProps or getServerSideProps. If you need global data fetching, consider incrementally adopting the app/ directory.

https://nextjs.org/docs/advanced-features/custom-app#caveats

You prolly need color scheme for your initial app loads, instead of every page server side request, that's why it is implemented on the App.getInitialProps

Control page initialization and add a layout that persists for all pages by overriding the default App component used by Next.js.