R
fn

useIntervalFn

testeddemo

Call a function on every interval. Supports reactive interval duration, pause/resume, and automatic cleanup on scope dispose.

Examples

ts
const { pause, resume, isActive } = useIntervalFn(() => {
  console.log('tick');
}, 1000);
ts
// Reactive interval
const delay = ref(1000);
useIntervalFn(() => console.log('tick'), delay);
delay.value = 500; // interval restarts with new duration

Demo

Loading demo…

Signature

ts
export function useIntervalFn(
  callback: () => void,
  interval: MaybeRefOrGetter<number> = 1000,
  options: UseIntervalFnOptions ={ ... }

Parameters

ParameterTypeDescription
callback() => voidFunction to call on every interval tick
interval?MaybeRefOrGetter<number>Function to call on every interval tick
options?UseIntervalFnOptionsConfiguration options

Returns

UseIntervalFnReturn