fn
refDebounced
v0.0.14testeddemoA readonly ref whose value mirrors a source but only after
updates stop arriving for ms. Wraps the source change in our debounce
primitive (built on debounceFilter), so rapid bursts collapse into a single
delayed write. Supports a maxWait ceiling so the value still progresses
under sustained input, and tears its timer down with the owning scope.
Examples
ts
const input = ref('');
const debounced = refDebounced(input, 300);
// debounced.value lags `input` by 300ms of quietts
// Guarantee the debounced value advances at least every 1000ms
const debounced = refDebounced(input, 300, { maxWait: 1000 });Demo
Loading demo…
Signature
ts
export function refDebounced<T>(
source: MaybeRefOrGetter<T>,
ms: MaybeRefOrGetter<number> = 200,
options: RefDebouncedOptions ={ ... }Type Parameters
TParameters
| Parameter | Type | Description |
|---|---|---|
source | MaybeRefOrGetter<T> | The ref, getter, or reactive source to debounce |
ms? | MaybeRefOrGetter<number> | Debounce delay in milliseconds (can be reactive) |
options? | RefDebouncedOptions | Debounce options (maxWait, rejectOnCancel) |
Returns
RefDebouncedReturn<T>A readonly ref tracking the source with debounced updates