adamsoffer/next-apollo

Add additional getInitialProps to withData

Closed this issue · 2 comments

There doesn't seem to be a way to add anything to the getInitialProps hook when using withData. I'm trying to figure out how to use part of the URL as an ID in my apollo query, but for that to work on the client side it needs to happen within the getInitialProps page hook, which is concealed by the withData HOC. Unless I am mistaken?

Actually it seems to call the wrapped PageComponents getInitialProps from the server as expected on first page load, but if you get to the page through browser only navigation (not sure what to call this, but using the next router or a Link component so there is no server side rendering involved) then getInitialProps isn't called. When I remove the withData HOC, getInitialProps runs in both situations, on the server for a SSR or in the browser otherwise.
I'm getting around this now by grabbing the query from the router when it's browser rendered.

Yeah you can't use getInitialProps on a page that uses the HOC