R
fn

useTimeoutFn

v0.0.15testeddemo

Call a function after a given delay, with manual `start`/`stop` control and a reactive `isPending` flag. SSR-safe and cleans up on scope dispose.

Examples

ts
const { isPending, start, stop } = useTimeoutFn(() => {
  console.log('fired');
}, 1000);
ts
// Fire once now and again after the delay
useTimeoutFn(refresh, 5000, { immediateCallback: true });

Demo

Loading demo…

Signature

ts
export function useTimeoutFn<T extends AnyFunction>(
  cb: T,
  interval: MaybeRefOrGetter<number>,
  options: UseTimeoutFnOptions ={ ... }

Type Parameters

Textends AnyFunction

Parameters

ParameterTypeDescription
cbTThe function to call after the timeout
intervalMaybeRefOrGetter<number>Delay in milliseconds (resolved each time `start` runs, can be reactive)
options?UseTimeoutFnOptionsOptions

Returns

UseTimeoutFnReturn<Parameters<T>>Timeout controls