useDebounceCallback
Custom hook that creates a debounced version of a callback function.
Custom hook that creates a debounced version of a callback function.
Usage
import { useDebounceCallback } from "@tilt-legal/cubitt-components/utilities/hooks";
const debouncedCallback = useDebounceCallback(
(searchTerm) => {
// Perform search after user stops typing for 500 milliseconds
searchApi(searchTerm);
},
500
);
// Later in the component
debouncedCallback('react hooks'); // Will invoke the callback after 500 milliseconds of inactivity.API
Signature
declare function useDebounceCallback<T extends (...args: any) => ReturnType<T>>(func: T, delay?: number, options?: DebounceOptions): DebouncedState<T>;Parameters
| Parameter | Type | Description | Default |
|---|---|---|---|
func | T | The callback function to be debounced. | - |
delay | number | The delay in milliseconds before the callback is invoked ( milliseconds). | 500 |
[options] | DebounceOptions | Options to control the behavior of the debounced function. | - |
Return Value
| Value | Type | Description |
|---|---|---|
return | DebouncedState<T> | A debounced version of the original callback along with control functions. |