useThrottledSignal#

A read-only signal that follows source at most once per ms — steady updates while the source streams, instead of waiting for it to fall quiet. Cross-platform — import from @sigx/use.

TypeScript
import { signal, watch } from 'sigx';
import { useThrottledSignal } from '@sigx/use';

const scroll = { y: signal(0) };
const throttled = useThrottledSignal(() => scroll.y.value, 100);

watch(throttled, y => updateMinimap(y)); // at most once every 100ms

Both source and ms are MaybeSignal; the result is a ReadSignal<T> and ms defaults to 200. leading updates on the first change of a window; trailing delivers the last change of a window (both default true).

Signature#

TypeScript
function useThrottledSignal<T>(
    source: MaybeSignal<T>,
    ms?: MaybeSignal<number>,
    options?: UseThrottledSignalOptions,
): ReadSignal<T>;

type UseThrottledSignalOptions = ThrottleOptions;

Options#

OptionTypeDefaultDescription
leadingbooleantrueUpdate on the first change of a window.
trailingbooleantrueDeliver the last change of a window.

Platform: everywhere (setTimeout). Any pending update is cancelled when the owning scope disposes.

See also#