Skip to Content
ohooks

useInterval

Runs a callback repeatedly at a specified millisecond interval, pausing when delay is null.

Loading preview...

The useInterval hook executes a callback on a repeating timer and automatically pauses whenever delay is set to null, always invoking the latest callback without resetting the interval on every render.

Installation

pnpm dlx shadcn@latest add https://ohooks.vercel.app/r/useInterval.json

Usage

Examples

Pausable Stopwatch

Pass null as the delay when paused so the interval is cleared until isRunning becomes true again.

Dynamic Tick Speed

Update the delay value reactively to speed up or slow down the interval on the fly.