Utility
useInterval
Declarative setInterval with automatic cleanup and pause/resume functionality.
import { useInterval } from "saha-ui"Uses
Declarative wrapper around setInterval that updates the callback reference and cleans up automatically.
Props
| Name | Type | Description | Default |
|---|---|---|---|
| callback | () => void | Function to call on each interval tick. | - |
| delay | number | null | Interval delay in ms; use null to pause the interval. | - |
Returns
| Name | Description |
|---|---|
| void | No return value; runs the callback according to the configured interval. |
Example
useInterval(() => setCount((c) => c + 1), 1000);
Notes
Keeps the latest callback in a ref so the interval uses the latest closure without recreating the interval when the callback changes.