From d8ba7270c800b3b25ebc5e941e703741cfc61092 Mon Sep 17 00:00:00 2001 From: yezy Date: Wed, 7 Jul 2021 16:38:51 +0200 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=93=9DUpdate=20README.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0815b74..1162e6d 100644 --- a/README.md +++ b/README.md @@ -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)
From 4a4f6241119db067f8e16787d0938de18b030802 Mon Sep 17 00:00:00 2001 From: yezy Date: Wed, 7 Jul 2021 16:39:53 +0200 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9A=A1=EF=B8=8FRun=20useEffect=20only=20?= =?UTF-8?q?on=20mount=20and=20unmount?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useGlobalStateReducer.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/hooks/useGlobalStateReducer.js b/src/hooks/useGlobalStateReducer.js index 5c7d9d9..e27b8ab 100644 --- a/src/hooks/useGlobalStateReducer.js +++ b/src/hooks/useGlobalStateReducer.js @@ -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);