R
fn

refDebounced

v0.0.15testeddemo

A 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 quiet
ts
// 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

T

Parameters

ParameterTypeDescription
sourceMaybeRefOrGetter<T>The ref, getter, or reactive source to debounce
ms?MaybeRefOrGetter<number>Debounce delay in milliseconds (can be reactive)
options?UseDebounceFnOptionsDebounce options (`maxWait`, `rejectOnCancel`)

Returns

Readonly<Ref<T, T>>A readonly ref tracking the source with debounced updates