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

Function useGetSet

src/useGetSet.ts:5–21  ·  view source on GitHub ↗
(
  initialState: IHookStateInitAction<S>
)

Source from the content-addressed store, hash-verified

3import { IHookStateInitAction, IHookStateSetAction, resolveHookState } from './misc/hookState';
4
5export default function useGetSet<S>(
6 initialState: IHookStateInitAction<S>
7): [get: () => S, set: Dispatch<IHookStateSetAction<S>>] {
8 const state = useRef(resolveHookState(initialState));
9 const update = useUpdate();
10
11 return useMemo(
12 () => [
13 () => state.current as S,
14 (newState: IHookStateSetAction<S>) => {
15 state.current = resolveHookState(newState, state.current);
16 update();
17 },
18 ],
19 []
20 );
21}

Callers 3

DemoFunction · 0.90
useCounterFunction · 0.85
setUpFunction · 0.85

Calls 2

resolveHookStateFunction · 0.90
useUpdateFunction · 0.85

Tested by 1

setUpFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…