function useAsyncDebouncedCallback<TFn, TSelected>(
fn,
options,
selector): (...args) => Promise<ReturnType<TFn>>
function useAsyncDebouncedCallback<TFn, TSelected>(
fn,
options,
selector): (...args) => Promise<ReturnType<TFn>>
Defined in: react-pacer/src/async-debouncer/useAsyncDebouncedCallback.ts:46
A React hook that creates a debounced version of an async callback function. This hook is a convenient wrapper around the useAsyncDebouncer hook, providing a stable, debounced async function reference for use in React components.
The debounced async function will only execute after the specified wait time has elapsed since its last invocation. If called again before the wait time expires, the timer resets and starts waiting again. The returned function always returns a promise that resolves or rejects with the result of the original async function.
This hook provides a simpler API compared to useAsyncDebouncer, making it ideal for basic async debouncing needs. However, it does not expose the underlying AsyncDebouncer instance.
For advanced usage requiring features like:
Consider using the useAsyncDebouncer hook instead.
• TFn extends AnyAsyncFunction
• TSelected = {}
TFn
AsyncDebouncerOptions<TFn>
(state) => TSelected
Function
...Parameters<TFn>
Promise<ReturnType<TFn>>
// Debounce an async search handler
const handleSearch = useAsyncDebouncedCallback(async (query: string) => {
const results = await fetchSearchResults(query);
return results;
}, {
wait: 500 // Wait 500ms between executions
});
// Use in an input
<input
type="search"
onChange={e => handleSearch(e.target.value)}
/>
// Debounce an async search handler
const handleSearch = useAsyncDebouncedCallback(async (query: string) => {
const results = await fetchSearchResults(query);
return results;
}, {
wait: 500 // Wait 500ms between executions
});
// Use in an input
<input
type="search"
onChange={e => handleSearch(e.target.value)}
/>
Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.