Return a debounced version of the provided callback function.
const debouncedCallback = useDebouncedCallback(callback, { delay: 500 });
Raw value: —
Debounced callback result: —
import { useDebouncedCallback } from 'kitzo'; import { useState } from 'react'; function SearchInput() { const [value, setValue] = useState(''); const debouncedSearch = useDebouncedCallback((query: string) => { // fire API call here with query console.log("Searching for:", query); }, { delay: 500 }); return ( <input value={value} onChange={(e) => { setValue(e.target.value); debouncedSearch(e.target.value); }} /> ); }
| Parameter | Type | Description |
|---|---|---|
callback | function | The function to debounce |
options | object | Options object containing delay, leading, and trailing |
options.delay | number | Delay in milliseconds (default: 300) |
options.leading | boolean | Call on the leading edge of the timeout (default: false) |
options.trailing | boolean | Call on the trailing edge of the timeout (default: true) |
Returns a debounced version of the callback, with additionalcancel and flush methods attached.
cancel to clear the timeout and flush to execute immediately.leading and trailing edge execution.