Skip to content

useTimeout ​

A hook that handles the setTimeout timer function.

Code demonstration ​

API ​

typescript
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 ​

Source · Document · Demo

Released under the MIT License.