useIntervalFn#

Run cb every interval ms (default 1000), returning a Pausable to control it. Cross-platform — import from @sigx/use.

TypeScript
import { useIntervalFn } from '@sigx/use';

const { pause, resume, isActive } = useIntervalFn(() => tick(), 1000);
pause();  // stop ticking; isActive.value === false
resume(); // start again

A reactive interval restarts the running timer whenever it changes — pass a signal or getter to drive the cadence from state:

TypeScript
import { signal } from 'sigx';
import { useIntervalFn } from '@sigx/use';

const period = signal(1000);
useIntervalFn(() => poll(), period);
period.value = 250; // timer restarts at the new period

The timer clears automatically with the owning scope (component setup or the innermost effectScope()); pause()/resume() control it manually.

Signature#

TypeScript
function useIntervalFn(
    cb: () => void,
    interval?: MaybeSignal<number>,
    options?: UseIntervalFnOptions,
): Pausable;

Options#

OptionTypeDefaultDescription
immediatebooleantrueStart the timer on creation.
immediateCallbackbooleanfalseAlso invoke cb right away whenever the timer (re)starts.

Returns#

A Pausable:

FieldTypeDescription
isActiveReadSignal<boolean>Whether the timer is currently running.
pause() => voidStop the timer.
resume() => voidStart the timer.

Platform: everywhere (setInterval).

See also#