useDebounceCallback
Custom hook that creates a debounced version of a callback function.
Installation
npx sse-hooks add use-debounce-callback
yarn dlx sse-hooks add use-debounce-callback
pnpm dlx sse-hooks add use-debounce-callback
deno run -A npm:sse-hooks add use-debounce-callback
bunx sse-hooks add use-debounce-callback
Usage
example.ts
import { useDebounceCallback } from "./{hooks file}";
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
Parameters
| Prop | Default | Type |
|---|---|---|
options | - |
Options to control the behavior of the debounced function.
|
func | - |
The callback function to be debounced. |
delay |
|
The delay in milliseconds before the callback is invoked (default is |
Returns
| Return Value | Default | Type |
|---|---|---|
return | - |
Hook return value |
Types Aliases
No specific type aliases defined for this component.