MCPcopy Index your code
hub / github.com/streamich/react-use / useSetState

Function useSetState

src/useSetState.ts:3–14  ·  view source on GitHub ↗
(
  initialState: T = {} as T
)

Source from the content-addressed store, hash-verified

1import { useCallback, useState } from 'react';
2
3const useSetState = <T extends object>(
4 initialState: T = {} as T
5): [T, (patch: Partial<T> | ((prevState: T) => Partial<T>)) => void] => {
6 const [state, set] = useState<T>(initialState);
7 const setState = useCallback((patch) => {
8 set((prevState) =>
9 Object.assign({}, prevState, patch instanceof Function ? patch(prevState) : patch)
10 );
11 }, []);
12
13 return [state, setState];
14};
15
16export default useSetState;

Callers 5

DemoFunction · 0.90
useSliderFunction · 0.85
useCopyToClipboardFunction · 0.85
createHTMLMediaHookFunction · 0.85
setUpFunction · 0.85

Calls 1

setFunction · 0.70

Tested by 1

setUpFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…