useInterval
Declarative timer with start, pause, and dynamic delay controls.
1.9 KB
•Updated on September 3, 2026
Example 2: Server Polling Simulator
Installation
Bash
pnpm dlx shadcn@latest add @spaceui/hooks-lifecycle-use-intervalUsage
Code
import { useInterval } from '@/hooks/use-interval'
const { start, stop } = useInterval(() => tick(), 1000)API Reference
Parameters / Props
| Parameter | Type | Default | Description |
|---|---|---|---|
callback | () => void | required | Tick function. |
delay | number|null | null | Delay in ms. |
Return Value
| Property | Type | Description |
|---|---|---|
start | (delay?: number) => void | Starts interval. |
stop | () => void | Pauses interval. |