mirror of
https://github.com/streamich/react-use.git
synced 2026-01-18 14:06:52 +00:00
commit
dc6df606dc
@ -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];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user