Skip to content

Commit

Permalink
Merge pull request #81 from yezyilomo/run_effect_on_mount_and_unmount
Browse files Browse the repository at this point in the history
Run effect on mount and unmount
  • Loading branch information
yezyilomo authored Jul 7, 2021
2 parents 3185cf8 + 4a4f624 commit b376121
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ React state management library based on global variables and react hooks.
- Support selecting deeply nested state
- Support creating global state dynamically
- Support both key based and non-key based global state
- States are stored as global variables(They can be used anywhere)
- States are stored as global variables(Can be used anywhere)

<br/>

Expand Down
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 b376121

Please sign in to comment.