facebookarchive / redux-react-hook

React Hook for accessing state and dispatch from a Redux store
MIT License
2.16k stars 103 forks source link

subscribe parent first #32

Closed nmn closed 5 years ago

nmn commented 5 years ago

I'm not sure about this. This was just a quick and dirty thing that popped into my head. I will try to test if this works sometime.

But I think this should hopefully ensure that at least on the first render, a parent will subscribe to changes before the child. Things get messy if the store needs to resubscribe for some reason.

ianobermiller commented 5 years ago

The subscribe call thas to be in useEffect for it to work correctly. redux-react goes through a lot of effort to make sure parents are re-rendered first, and I'm not sure we can even do that with a hook, or that we want to. We had this same problem in Proton at first, but making our connected components resilient to being re-rendered before their parents was worth doing anyway.

Since I don't think we want to add this behavior (@gaearon recommended against it), I'm going to close this PR. Thanks, though, for bringing it up!