useDebouncedCallback()function
useDebouncedCallback(callback: (() => void) | undefined, delay = 500): () => void
| Param | Type | |
|---|---|---|
callback | (() => void) | The callback to debounce (may be undefined to no-op). |
delay | unknown | The debounce delay in milliseconds (defaults to 500). Defaults to 500 |
| Return | |
|---|---|
() => void | A debounced function that schedules callback after delay. |
Wrap a callback so it only runs after a debounce delay since the last invocation.
- Each call resets the timer, so the callback fires once
delaymilliseconds have passed without another call — useful for auto-submitting a form after the user stops typing. - Pending timeouts are cleared automatically on unmount.
Examples
const submit = useDebouncedCallback(() => form.submit());