the-road-to-learn-react / use-combined-reducers

Custom hook to combine all useReducer hooks for one global state container.
https://www.robinwieruch.de
MIT License
75 stars 9 forks source link

dispatch changes reference on every call. #4

Open amsterdamharu opened 4 years ago

amsterdamharu commented 4 years ago

If I want to to use dispatch in an effect then dispatch is a dependency and since dispatch changes on every call to useCombinedReducers the effect will be called every time.

A stack overflow issue can be found here.

The pull request is here

Tsourdox commented 4 years ago

This is actually easily solved with the useRef hook. Check the PR for more info, I made a comment there :)