useInterval

A hook that handles the setInterval timer function.

Examples

Default usage

count:0

Basic usage

Execute once per 1000ms.

Advanced usage

count:0

interval:1000

Advanced usage

Modify the delay to realize the timer interval change and pause.

API

const { clear, start } = useInterval(  fn: () => void,  delay?: number | undefined,  options?: Options): fn: () => void;
const { clear, start } = 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.number | undefined | (() => number | undefined) | Accessor<number | undefined>
optionsConfig of the interval behavior.Options

Options

PropertyDescriptionTypeDefault
immediateWhether the function should be executed immediately on first executionbooleanfalse

Result

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