DataInterface hooks
useDebouncedValue
The value once it has stopped changing for ms (header search, list search boxes).
import { useDebouncedValue } from '@ergasti/bricks';Examples
Debounce a value
The returned value follows the input only after ms of quiet (400 here): useful for a request key.
Code
import { useState } from 'react';
import { useDebouncedValue } from '@ergasti/bricks';
function Delayed() {
const [text, setText] = useState('');
const settled = useDebouncedValue(text, 400);
return (
<div style={{ display: 'grid', gap: 6, maxWidth: 320 }}>
<input aria-label="Type here" placeholder="Type here" value={text} onChange={(e) => setText(e.target.value)} />
<small>Now: “{text}” · settled: “{settled}”</small>
</div>
);
}Signature
function useDebouncedValue<T>(value: T, ms?: number): TParameters
Prop
Type
Returns
T
Related
useFocusTrap · useIsMobile · useModalLock · useOpenedRow
Source
src/hooks/useDebouncedValue.ts (line 6) on GitHub.