diegohaz / constate

React Context + State

Home Page:https://codesandbox.io/s/github/diegohaz/constate/tree/master/examples/counter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is there a working demo with NextJS?

dpyzo0o opened this issue · comments

More specifically, I would like to consume some global values in getInitialProps but then I would get this error Error: Invalid hook call. Hooks can only be called inside of the body of a function component. . e.g with redux, I'm able to access the redux store inside getInitialProps. Any ideas that could achieve this?

Possibly related #68

commented

It's not possible to use it outside of the render phase of React components. What you can do, though, is creating your initial state in getInitialProps and then pass it to React Context in the render phase like this: #68 (comment)