MCPcopy Create free account
hub / github.com/ColmapView/Colmapview.github.io / useResetKeyedState

Function useResetKeyedState

src/hooks/useResetKeyedState.ts:35–54  ·  view source on GitHub ↗
(
  resetKey: unknown,
  initialValue: T
)

Source from the content-addressed store, hash-verified

33}
34
35export function useResetKeyedState<T>(
36 resetKey: unknown,
37 initialValue: T
38): [T, Dispatch<SetStateAction<T>>] {
39 const [state, dispatch] = useReducer(resetKeyedStateReducer<T>, {
40 resetKey,
41 value: initialValue,
42 });
43
44 const setValue = useCallback<Dispatch<SetStateAction<T>>>((action) => {
45 dispatch({ type: 'set', action });
46 }, []);
47
48 if (!Object.is(state.resetKey, resetKey)) {
49 dispatch({ type: 'reset', resetKey, value: initialValue });
50 return [initialValue, setValue];
51 }
52
53 return [state.value, setValue];
54}

Callers 7

DistanceInputModalFunction · 0.90
DeletionModal.tsxFile · 0.90
GlobalContextMenuFunction · 0.90
useModalDragFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected