useDebouncedValue
useDebouncedValue returns a copy of a value that only updates after delay ms have elapsed without further changes — “wait until the user stops typing” for search inputs, autosave drafts, and expensive selector derivations.
Live preview
Import
Section titled “Import”import { useDebouncedValue } from 'entangle-ui';Signature
Section titled “Signature”function useDebouncedValue<T>(value: T, delay: number): T;function Search() { const [text, setText] = useState(''); const debounced = useDebouncedValue(text, 250);
useEffect(() => { if (debounced) runQuery(debounced); }, [debounced]);
return ( <Input value={text} onChange={event => setText(event.currentTarget.value)} /> );}Driving a query
Section titled “Driving a query”Search
Arguments
Section titled “Arguments”| Prop | Type | Default | Description |
|---|---|---|---|
value * | T | — | The value to debounce. The hook re-runs its timer every time this changes. |
delay * | number | — | Debounce window in milliseconds. Values `<= 0` skip the timer and pass the value through synchronously. |
Return value
Section titled “Return value”The hook returns the latest stable value of the same type as value. The reference only changes when the debounce timer fires.
Related
Section titled “Related”useDebouncedCallback— debounce a function instead of a value, withcancel/flushcontrols.useThrottledCallback— for rate-limiting rather than waiting for quiescence.
Common pitfalls
Section titled “Common pitfalls”- Effects keyed on
value: if you haveuseEffect(() => …, [value])and adduseDebouncedValue, key the effect on the debounced value, not the raw one. Otherwise the effect still fires on every keystroke. - Initial render: the first returned value equals the input — there is no
undefinedwarmup phase. Code can treat the result as always present. - Delay of
0: values flow through synchronously. Useful for runtime-tunable delays where0should mean “no debounce”.