useDelay
Executes a callback after a configurable delay. Supports both automatic execution on mount and manual trigger mode.
Signature
function useDelay(
callback: () => void,
options?: { delay?: number; manual?: boolean }
): () => void | undefined
Options
| Property | Type | Default | Description |
|---|---|---|---|
delay | number | 250 | Milliseconds before the callback fires |
manual | boolean | false | When true, the hook returns a trigger function instead of auto-executing |
Return value
| Mode | Return | Description |
|---|---|---|
manual: false | () => {} | No-op (auto-executes on mount) |
manual: true | () => void | undefined | Call this to start the delayed execution |
The cleanup function can also cancel a pending timeout if called before the delay elapses.
Live example
Loading playground...