MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / useDebounceState

Function useDebounceState

apps/start/src/hooks/use-debounce-state.ts:10–30  ·  view source on GitHub ↗
(
  initialValue: T,
  delay = 500,
  options?: Parameters<typeof debounce>[2],
)

Source from the content-addressed store, hash-verified

8}
9
10export function useDebounceState<T>(
11 initialValue: T,
12 delay = 500,
13 options?: Parameters<typeof debounce>[2],
14): DebouncedState<T> {
15 const [value, setValue] = useState<T>(initialValue);
16 const [debouncedValue, _setDebouncedValue] = useState<T>(initialValue);
17 const setDebouncedValue = useMemo(
18 () => debounce(_setDebouncedValue, delay, options),
19 [],
20 );
21 useEffect(() => {
22 setDebouncedValue(value);
23 }, [value]);
24
25 return {
26 value,
27 debounced: debouncedValue,
28 set: setValue,
29 };
30}

Callers 2

EventListenerFunction · 0.90
useLiveCounterFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected