fn
refThrottled
v0.0.14testeddemoA 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 = unknown>(
source: MaybeRefOrGetter<T>,
delay = 200,
trailing = true,
leading = true,
): RefThrottledReturn<T>{ ... }Type Parameters
T= unknownParameters
| Parameter | Type | Description |
|---|---|---|
source | MaybeRefOrGetter<T> | The ref, getter, or value to watch and throttle |
delay? | number | A zero-or-greater delay in milliseconds; values around 100–250 (or higher) are most useful |
trailing? | boolean | Update the value again on the trailing edge after the window elapses |
leading? | boolean | Update the value on the leading edge of the window |
Returns
RefThrottledReturn<T>A ref reflecting the throttled source value