Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why does withLayout need to call it's child's getInitialProps method? #185

Closed
orpheus opened this issue Jan 8, 2019 · 4 comments
Closed
Assignees

Comments

@orpheus
Copy link

orpheus commented Jan 8, 2019

For instance, /pages/customer/my-books has a getInitialProps and it is wrapped with withLayout HOC. withLayout calls the getInitialprops of my-books js, but if you comment it out in the HOC, my-books won't run getInitialProps itself. How is it determined when getInitialProps will run. The docs aren't very clear. I was under the impression that each component calls it's own getInitialProps right before it's about to get rendered.

@orpheus
Copy link
Author

orpheus commented Jan 8, 2019

found this, hopefully it may help others: vercel/next.js#159 (comment)

@orpheus orpheus closed this as completed Jan 8, 2019
@orpheus orpheus reopened this Jan 8, 2019
@orpheus
Copy link
Author

orpheus commented Jan 8, 2019

not sure whether to keep this open or closed so people can see it or not... I'll let admins decide

@tima101 tima101 added the Assigned - Async Issue is assigned to at least one person. PR is assigned to at least one person. label Jan 15, 2019
@tima101
Copy link
Member

tima101 commented Jan 15, 2019

@orpheus Thanks for your question and answer.

I think we should add this explanation to the book.
Note to self: vercel/next.js#159 (comment)

I will close this issue after we add an explanation to book's text.

@tima101
Copy link
Member

tima101 commented Mar 13, 2019

@orpheus Thanks for researching and posting explanation.

Here is another link:
vercel/next.js#1074 (comment)

You have to define getInitialProps on the top level component, and pass down props to descendant components.

Your original link:
vercel/next.js#159 (comment)

Few things to remember about getInitialProps:

  • you can't use getInitialProps in non-page components, only in page components
  • you have to define getInitialProps in HOC (higher-order component) and pass down data to wrapped page component

@tima101 tima101 added Ready to test - Async Issue is implemented and ready for testing. PR is merged. and removed Assigned - Async Issue is assigned to at least one person. PR is assigned to at least one person. labels Mar 13, 2019
@tima101 tima101 removed the Ready to test - Async Issue is implemented and ready for testing. PR is merged. label Jun 10, 2019
@tima101 tima101 closed this as completed Jun 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants