Skip to content
On this page

useTimeout

A hook that handles the setTimeout timer function.

Code demonstration

API

useTimeout(
  fn: () => void,
  delay?: Ref<number | undefined> | number,
  options?:{
    immediate?: boolean
  }
): fn: () => void;
useTimeout(
  fn: () => void,
  delay?: Ref<number | undefined> | number,
  options?:{
    immediate?: boolean
  }
): fn: () => void;

Params

PropertyDescriptionType
fnThe function to be executed after delay milliseconds.() => void
delayThe number of milliseconds to wait before executing the function. The timer will be cancelled if delay is Ref<number | undefined >|number | undefined
immediateWhether the function should be executed immediately on first executionboolean

Result

PropertyDescriptionType
clearTimeoutclear timeout() => void

Source

SourceDocsDemo