cyberwombat
cyberwombat

Reputation: 40074

Calling getInitialProps in children using NextJs

I am implementing data fetching in Next.js using this example:

https://github.com/zeit/next.js/blob/master/examples/data-fetch/pages/index.js

I first tried it by adding the getInitialProps bit in one of my components but it does not get called unless I put it in one of the main pages. I read some somewhat related discussions that I may need to call the children's getInitialProps from the pages/parent getInitialProps but not clear on how to do so. Also I am wondering if perhaps I should keep the call in the page itself as far as proper technique.

Upvotes: 2

Views: 2705

Answers (1)

cyberwombat
cyberwombat

Reputation: 40074

Ah.. right from he NextJS docs :)

Note: getInitialProps can not be used in children components. Only in pages.

Upvotes: 5

Related Questions