fn
useDebounceFn
v0.0.15testeddemoDebounce execution of a function — a thin reactive wrapper around `@robonen/stdlib`'s `debounce`. Postpones invocation until `ms` have elapsed since the last call and resolves with the wrapped function's result. Supports a reactive delay, a `maxWait` ceiling, `rejectOnCancel`, and exposes `cancel`, `flush`, and `isPending`. Pending timers are cleared on scope dispose.
Examples
ts
const search = useDebounceFn(() => fetchResults(query.value), 300);
watch(query, search);ts
const save = useDebounceFn(persist, 300, { maxWait: 1000 });
save.cancel();
save.flush();
if (save.isPending.value) {}Demo
Loading demo…
Signature
ts
export function useDebounceFn<T extends AnyFunction>(
fn: T,
ms: MaybeRefOrGetter<number> = 200,
options: UseDebounceFnOptions ={ ... }Type Parameters
Textends AnyFunctionParameters
| Parameter | Type | Description |
|---|---|---|
fn | T | The function to debounce |
ms? | MaybeRefOrGetter<number> | Delay in milliseconds (can be reactive) |
options? | UseDebounceFnOptions | Debounce options (`maxWait`, `rejectOnCancel`) |
Returns
UseDebounceFnReturn<T>The debounced function with `cancel`, `flush`, and `isPending`