useIntervalFn
Execute a function repeatedly at a given interval with reactive isActive state and pause/resume control.
Returns a Pausable — isActive is a ReadonlyObservable<boolean>.
Hello
import { import useIntervalFn
useIntervalFn } from "@usels/web";
const { const isActive: any
isActive, const pause: any
pause, const resume: any
resume } = import useIntervalFn
useIntervalFn(() => { any
console.any
log("tick");}, 1000);
// isActive.get() === true while running// pause() / resume() to control executionimmediateCallback
Section titled “immediateCallback”import { import useIntervalFn
useIntervalFn } from "@usels/web";
import useIntervalFn
useIntervalFn(() => any
fetchData(), 5000, { immediateCallback: boolean
immediateCallback: true });// calls fetchData() immediately on resume, then every 5sReactive interval
Section titled “Reactive interval”import { import useIntervalFn
useIntervalFn } from "@usels/web";import { function observable<T>(): Observable<T | undefined> (+2 overloads)
observable } from "@legendapp/state";
const const ms$: any
ms$ = observable<unknown>(value: Promise<unknown> | (() => unknown) | unknown): any (+2 overloads)
observable(1000);import useIntervalFn
useIntervalFn(() => {}, const ms$: any
ms$);// ms$.set(500) → automatically restarts with new intervalinterval must be a positive number. 0 or negative values are passed directly to setInterval, which the browser clamps to ~4ms. Use pause() to stop execution instead of setting interval to 0.
Type Declarations
Section titled “Type Declarations”export interface UseIntervalFnOptions { immediate?: boolean; immediateCallback?: boolean;}export declare function useIntervalFn(cb: AnyFn, interval?: MaybeObservable<number>, options?: UseIntervalFnOptions): Pausable;Source
Section titled “Source”Contributors
Section titled “Contributors”- tigerwest
Changelog
Section titled “Changelog”a7392ab2026-03-06 - feat(core,browser): add sync strategy hooks (tigerwest)