Open omardoma opened 4 years ago
https://github.com/incipher/einmal/blob/fba4caaa0b0e8b7b762f365d1f8a6d4ac9f1ecd5/src/hooks/useGlobalState/reducer.ts#L27
The actions are being dispatched twice because the useReducer callback is always a new function, it can be solved by making the reduction function a function declaration/expression and passing its reference instead of inlining it.
See Here: https://www.reddit.com/r/reactjs/comments/av39fs/usereducer_action_dispatched_twice/
@omardoma Great catch, thanks a lot!
https://github.com/incipher/einmal/blob/fba4caaa0b0e8b7b762f365d1f8a6d4ac9f1ecd5/src/hooks/useGlobalState/reducer.ts#L27
The actions are being dispatched twice because the useReducer callback is always a new function, it can be solved by making the reduction function a function declaration/expression and passing its reference instead of inlining it.
See Here: https://www.reddit.com/r/reactjs/comments/av39fs/usereducer_action_dispatched_twice/