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];