Skip to content

Commit 83611a1

Browse files
author
landong.lk
committed
fix: useSetState bug
1 parent 094769c commit 83611a1

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

src/useSetState.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import {useState} from 'react';
33
const useSetState = <T extends object>(initialState: T = {} as T): [T, (patch: Partial<T> | Function) => void]=> {
44
const [state, set] = useState<T>(initialState);
55
const setState = patch => {
6-
if (patch instanceof Function) set(prevState => Object.assign({}, prevState, patch(prevState)));
7-
else set(Object.assign({}, state, patch));
6+
set(prevState => Object.assign({}, prevState, patch instanceof Function ? patch(prevState) : patch));
87
};
98

109
return [state, setState];

0 commit comments

Comments
 (0)