Skip to content
On this page

useInterval

A hook that handles the setInterval timer function.

Code demonstration

API

useInterval(
  fn: () => void,
  delay?: number | undefined,
  options?: Options
): fn: () => void;
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

SourceDocsDemo