Skip to content

Commit

Permalink
fix: useSetState bug
Browse files Browse the repository at this point in the history
  • Loading branch information
landong.lk committed Feb 22, 2019
1 parent 094769c commit 83611a1
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/useSetState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import {useState} from 'react';
const useSetState = <T extends object>(initialState: T = {} as T): [T, (patch: Partial<T> | Function) => void]=> {
const [state, set] = useState<T>(initialState);
const setState = patch => {
if (patch instanceof Function) set(prevState => Object.assign({}, prevState, patch(prevState)));
else set(Object.assign({}, state, patch));
set(prevState => Object.assign({}, prevState, patch instanceof Function ? patch(prevState) : patch));
};

return [state, setState];
Expand Down

0 comments on commit 83611a1

Please sign in to comment.