menu

Next.js

A place to chat about Next.js and answer questions. For all other ZEIT products, check this out.

Channels
Team

Need Explanation on getInitialProps Parameters

November 23, 2018 at 8:26am

Need Explanation on getInitialProps Parameters

November 23, 2018 at 8:26am

Hello, Next.js community! 👋🏻

I've search the Spectrum threads and GitHub issues, and so far I can't seem to find any explanation or details on the parameters and return values for getInitialProps method. Is there an official API documentation or any kind of reference explaining this? Thanks in advance.


November 23, 2018 at 8:52am

https://github.com/zeit/next.js/ go to the Fetching data and component lifecycle section

Edited
  • reply
  • like

No good docs, nextjs is not well documented

  • reply
  • like

You can use inspect(ctx) from getInitialProps(ctx) , it's easy to know what's going on.

  • reply
  • like

Especially when you compose multiple getInitialProps , very handy to debug things

  • reply
  • like

https://github.com/zeit/next.js/ go to the Fetching data and component lifecycle section

Yes, the readme already explains what parameters are availavle. But specifically, I need the IDE or editor to understand what exactly the parameters are and their types.

  • reply
  • like

Also, in this part of the readme [1], getInitialProps has these parameters { Component, router, ctx }, which Component and router parameter isn't documented on an earlier part of the readme[2].

[1] https://github.com/zeit/next.js/#custom-app

[2] https://github.com/zeit/next.js/#fetching-data-and-component-lifecycle

  • reply
  • like

You can use inspect(ctx) from getInitialProps(ctx) , it's easy to know what's going on.

inspect()? Where's that from?

  • reply
  • like
const {inspect} = require('util')
like-fill
2
  • reply
  • like

November 26, 2018 at 8:33am

Many thanks to

for recommending using util.inspect

  • reply
  • like