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

NameTypeDescriptionDefault
callback() => voidFunction to call on each interval tick.-
delaynumber | nullInterval delay in ms; use null to pause the interval.-

Returns

NameDescription
voidNo 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.
Saha UI - The Modern React Component Library