incipher / einmal

⏱ The two-factor authentication app you deserve
Creative Commons Zero v1.0 Universal
80 stars 5 forks source link

Bug: Actions are dispatched twice #4

Open omardoma opened 4 years ago

omardoma commented 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/

itsabdelrahman commented 4 years ago

@omardoma Great catch, thanks a lot!