fn
useTimeoutFn
v0.0.14testeddemoCall 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 AnyFunctionParameters
| Parameter | Type | Description |
|---|---|---|
cb | T | The function to call after the timeout |
interval | MaybeRefOrGetter<number> | Delay in milliseconds (resolved each time start runs, can be reactive) |
options? | UseTimeoutFnOptions | Options |
Returns
UseTimeoutFnReturn<Parameters<T>>Timeout controls| Property | Type | Description |
|---|---|---|
isPending | Readonly<Ref<boolean>> | Whether the timeout is currently pending |
start | (...args: Args) => void | Start (or restart) the timeout |
stop | () => void | Cancel the pending timeout |