esamattis / redux-hooks

⚓ React Hooks implementation for Redux
http://npm.im/@epeli/redux-hooks
MIT License
96 stars 4 forks source link

State of store can change before the provider subscribes #7

Closed joshjg closed 5 years ago

joshjg commented 5 years ago

Currently, there is a timing issue when children dispatch an action inside useEffect during their first render. Here's the order of events:

  1. Some consumer reads the initial value via useMapState
  2. A child of the provider dispatches an action inside useEffect
  3. The provider itself subscribes to the store via useEffect

As a result, consumers are not updated with the new state value. Here's how react-redux handles this: https://github.com/reduxjs/react-redux/blob/72ed6db1947913bdd4900b324243c43a490b4c5a/src/components/Provider.js#L56

esamattis commented 5 years ago

Thanks for bringing this up. Will look into it.

esamattis commented 5 years ago

Fix released in v0.5.4