Skip to content

useTimeout

A thin wrapper around useTimeoutFn that exposes a ReadonlyObservable<boolean> (ready$) that flips to true when the timeout completes.

Ready: false

Ready becomes true after 1 second.

import {
import useTimeout
useTimeout
} from "@usels/web";
const
const ready$: any
ready$
=
import useTimeout
useTimeout
(1000);
// ready$.get() === false while waiting
// ready$.get() === true after 1000ms
import {
import useTimeout
useTimeout
} from "@usels/web";
import useTimeout
useTimeout
(500, {
callback: () => any
callback
: () =>
any
console
.
any
log
("done!"),
});
import {
import useTimeout
useTimeout
} from "@usels/web";
const {
const ready$: any
ready$
,
const isPending$: any
isPending$
,
const stop: any
stop
,
const start: any
start
} =
import useTimeout
useTimeout
(1000, {
controls: boolean
controls
: true });
const stop: any
stop
(); // cancel the pending timeout
const start: any
start
(); // restart the timer
import {
import useTimeout
useTimeout
} from "@usels/web";
const {
const ready$: any
ready$
,
const start: any
start
} =
import useTimeout
useTimeout
(1000, {
controls: boolean
controls
: true,
immediate: boolean
immediate
: false,
});
// call start() when you're ready
const start: any
start
();
ObservableMeaning
ready$true when timeout has fired
isPending$ (controls only)true while timeout is still waiting

They are inverses: ready$ = !isPending$.

Pass an Observable<number> as the first argument and useTimeoutFn will read the latest value each time start() is called.

export interface UseTimeoutOptions<Controls extends boolean = false> {
controls?: Controls;
callback?: Fn;
immediate?: boolean;
}
export declare function useTimeout(interval?: MaybeObservable<number>, options?: UseTimeoutOptions<false>): ReadonlyObservable<boolean>;
export declare function useTimeout(interval: MaybeObservable<number>, options: UseTimeoutOptions<true>): {
ready$: ReadonlyObservable<boolean>;
} & Stoppable;

View on GitHub

  • tigerwest
  • a7392ab 2026-03-06 - feat(core,browser): add sync strategy hooks (tigerwest)