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
Property | Description | Type |
---|---|---|
fn | The function to be executed every delay milliseconds. | () => void |
delay | The 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> |
options | Config of the interval behavior. | Options |
Options
Property | Description | Type | Default |
---|---|---|---|
immediate | Whether the function should be executed immediately on first execution | boolean | false |
Result
Property | Description | Type |
---|---|---|
clear | clear interval | () => void |
start | start interval | () => void |