From afbacace24e76f58bd3318f01dfff462293a0295 Mon Sep 17 00:00:00 2001 From: streamich Date: Sun, 17 Feb 2019 09:14:25 +0100 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=F0=9F=90=9B=20fix=20typings=20in=20?= =?UTF-8?q?useOrientation=20sensor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/useOrientation.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/useOrientation.ts b/src/useOrientation.ts index eb6bf3dfc1..ebaa363d95 100644 --- a/src/useOrientation.ts +++ b/src/useOrientation.ts @@ -26,7 +26,7 @@ const useOrientation = (initialState: OrientationState = defaultState) => { setState({angle, type}); } else if (window.orientation) { setState({ - angle: window.orientation, + angle: typeof window.orientation === 'number' ? window.orientation : 0, type: '' }); } else { From 524abe5702198926a2021cda7941b0f4141ed6f3 Mon Sep 17 00:00:00 2001 From: streamich Date: Sun, 17 Feb 2019 09:19:40 +0100 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=F0=9F=90=9B=20fix=20useSetState=20a?= =?UTF-8?q?fter=20React=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As reported in #107 Issues: #107 --- src/__stories__/useSetState.story.tsx | 4 ++-- src/useSetState.ts | 12 +++--------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/__stories__/useSetState.story.tsx b/src/__stories__/useSetState.story.tsx index b8eb61fb49..b4cb7ce40e 100644 --- a/src/__stories__/useSetState.story.tsx +++ b/src/__stories__/useSetState.story.tsx @@ -11,14 +11,14 @@ const Demo = () => {
{JSON.stringify(state, null, 2)}
- ); diff --git a/src/useSetState.ts b/src/useSetState.ts index 77d7274b74..2ec750a83f 100644 --- a/src/useSetState.ts +++ b/src/useSetState.ts @@ -2,15 +2,9 @@ import {useState} from 'react'; const useSetState = (initialState: T = {} as T): [T, (patch: Partial | Function) => void]=> { const [state, set] = useState(initialState); - const setState = (patch) => { - if (patch instanceof Function) { - set((prevState) => { - return Object.assign(state, patch(prevState)) - }) - } else { - Object.assign(state, patch); - set(state); - } + const setState = patch => { + if (patch instanceof Function) set(prevState => Object.assign({}, prevState, patch(prevState))); + else set(Object.assign({}, state, patch)); }; return [state, setState];