one-hook
Size
0.40 kb
View source

useInterval

setInterval reactified, with synchronization support.

Installation

npm install @1hook/use-interval

Usage

import {  } from '@1hook/use-interval'

Set an interval:

const { , ,  } = (() => {
  .('Hello')
}, 1000)

Pause the interval by setting the delay to null:

(() => .('Hello'), null)

Execute immediately by setting the leading option to true:

(() => .('Hello'), 1000, { : true })

Synchronize all intervals that share the same delay using the sync option:

(() => .('Hello'), 1000, { : true })

API Reference

UseIntervalOptions

Options for the useInterval hook (3rd argument).

PropTypeDefault
sync?
boolean
false
leading?
boolean
false

UseIntervalReturn

Return value of the useInterval hook.

PropTypeDefault
reset
() => void
-
cancel
() => void
-
isPending
boolean
-

On this page