Skip to main content
Version: 0.1.0

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

PropertyTypeDefaultDescription
delaynumber250Milliseconds before the callback fires
manualbooleanfalseWhen true, the hook returns a trigger function instead of auto-executing

Return value

ModeReturnDescription
manual: false() => {}No-op (auto-executes on mount)
manual: true() => void | undefinedCall 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...