Skip to content

useInterval ​

A hook that handles the setInterval timer function.

Code demonstration ​

API ​

typescript
useInterval(
  fn: () => void,
  delay?: number | undefined,
  options?: Options
): fn: () => void;

Params ​

PropertyDescriptionType
fnThe function to be executed every delay milliseconds.() => void
delayThe time in milliseconds, the timer should delay in between executions of the specified function. The timer will be cancelled if delay is set to undefined.Ref<number>|number | undefined
optionsConfig of the interval behavior.Options

Options ​

PropertyDescriptionTypeDefault
immediateWhether the function should be executed immediately on first execution.booleanfalse

Result ​

PropertyDescriptionType
clearclear interval() => void
restartrestart interval() => void

Source ​

Source · Document · Demo

Released under the MIT License.