MCPcopy Create free account
hub / github.com/code100x/cms / useDebounce

Function useDebounce

src/hooks/useDebounce.ts:3–17  ·  view source on GitHub ↗
(value: T, delay: number)

Source from the content-addressed store, hash-verified

1import { useEffect, useState } from 'react';
2
3export function useDebounce<T>(value: T, delay: number): T {
4 const [debouncedValue, setDebouncedValue] = useState<T>(value);
5
6 useEffect(() => {
7 const handler = setTimeout(() => {
8 setDebouncedValue(value);
9 }, delay);
10
11 return () => {
12 clearTimeout(handler);
13 };
14 }, [value, delay]);
15
16 return debouncedValue;
17}

Callers 1

SearchBarFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected