Skip to Content
⭐️ Leave a star →
HooksuseInterval

useInterval

A managed setInterval. Pass delay = null to pause without unmounting. The latest callback reference is always invoked, so closure-captured values stay fresh.

Used internally by Timeago for its periodic re-render.

import { useState } from 'react' import { useInterval } from '@wire-ui/react' function Ticker() { const [count, setCount] = useState(0) const { isRunning, start, stop } = useInterval(() => setCount((c) => c + 1), 1000, { autoStart: true, }) return ( <> <span>{count}</span> <button onClick={isRunning ? stop : start}> {isRunning ? 'Pause' : 'Resume'} </button> </> ) }

Parameters

ParamTypeDescription
callback() => voidFires on every tick.
delaynumber | nullMilliseconds between ticks. null pauses the interval.
options{ autoStart?: boolean, immediate?: boolean }autoStart runs on mount; immediate fires the callback once on start.

Returns

KeyTypeDescription
isRunningbooleantrue while the interval is active.
start() => voidBegin ticking.
stop() => voidPause ticking.
reset() => voidCancel and restart with the current delay.
Last updated on

MIT License © 2026 wire-ui

useInterval – Wire UI