Skip to content

Commit

Permalink
⚡️Run useEffect only on mount and unmount
Browse files Browse the repository at this point in the history
  • Loading branch information
yezyilomo committed Jul 7, 2021
1 parent d8ba727 commit 4a4f624
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/hooks/useGlobalStateReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ function useGlobalStateReducer(reducer, globalState, config = {}) {
useEffect(() => {
globalState.subscribe(observer);
isMounted.current = true;

return () => {
globalState.unsubscribe(observer);
isMounted.current = false;
}
})
}, [])

function dispatch(action) {
const newState = reducer(globalState.getValue(), action);
Expand Down

0 comments on commit 4a4f624

Please sign in to comment.