Patina

Command Palette

Search for a command to run...

Sign inGet Pro

Artifact

pro

Panel for generated code and documents with copy, download, and a file badge.

use-debounced-value.ts

10 lines · 0.3 KB

ts
export function useDebouncedValue<T>(value: T, delay = 300) {
  const [debounced, setDebounced] = useState(value);

  useEffect(() => {
    const id = setTimeout(() => setDebounced(value), delay);
    return () => clearTimeout(id);
  }, [value, delay]);

  return debounced;
}