Closed vans163 closed 5 years ago
Oh, good catch. Let me see...
Yeah, it's queued. Thought it shouldn't be a problem because we don't expose state like getGlobalState
, ...until I saw your hack in #15.
setGlobalState
was added later to the API, which I now think, in a bad manner. It's easy to break things.
Could you let me know your use case when you need to setGlobalState on startup?
And I realize a possible bug in the case of createGlobalStore. 😱
The queuing was the bad idea of mine. Fixed now.
It should work both with setGlobalState
and dispatch
.
The test code was also added.
About reading global state, let's continue discussion in #15.
Published: https://www.npmjs.com/package/react-hooks-global-state/v/0.11.0
There might still be some edge cases, especially with react-hot-loader. Feedback is welcome.
Thanks again! @vans163
setGlobalState was added later to the API, which I now think, in a bad manner.
Correction: It's not bad, but it has to be used carefully. The API doesn't force it and there's no good document.
It seems if I call during the first render setGlobalState, it does not proc. But useGlobalState works. Maybe setGlobalState gets queued until the end of render, in which case I need to set something before render is done.