R
fn

refThrottled

v0.0.15testeddemo

A ref whose value updates are throttled. The returned ref mirrors the source but propagates changes at most once per `delay` window, making it useful for rate-limiting reactive updates driven by high-frequency events such as `scroll` or `resize`.

Examples

ts
const input = ref('');
const throttled = refThrottled(input, 1000);
ts
const scrollY = ref(0);
const throttledY = refThrottled(scrollY, 100, true, false);

Demo

Loading demo…

Signature

ts
export function refThrottled<T = any>(
  source: MaybeRefOrGetter<T>,
  delay = 200,
  trailing = true,
  leading = true,
): RefThrottledReturn<T>{ ... }

Type Parameters

T= any

Parameters

ParameterTypeDescription
sourceMaybeRefOrGetter<T>The ref, getter, or value to watch and throttle
delay?numberA zero-or-greater delay in milliseconds; values around 100–250 (or higher) are most useful
trailing?booleanUpdate the value again on the trailing edge after the window elapses
leading?booleanUpdate the value on the leading edge of the window

Returns

RefThrottledReturn<T>A ref reflecting the throttled source value