useDebouncedSignal#

A read-only signal that trails source, collapsing a burst of rapid changes into a single update once things settle. Cross-platform — import from @sigx/use.

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

const query = signal('');
const debounced = useDebouncedSignal(query, 300);

watch(debounced, q => search(q)); // fires 300ms after the last keystroke

Both source and ms are MaybeSignal — pass a reactive ms to change the window on the fly. The result is a ReadSignal<T>; ms defaults to 200.

Use maxWait to guarantee an update even while the source never stops changing — an upper bound on how long the debounced signal will lag behind.

Signature#

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

interface UseDebouncedSignalOptions {
    maxWait?: number;
}

Options#

OptionTypeDefaultDescription
maxWaitnumberUpper bound (ms) between updates while the source keeps changing.

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

See also#