Skip to Content
ohooks

useTimeout

Declarative setTimeout hook that invokes a callback after delay milliseconds.

Loading preview...

The useTimeout hook schedules a callback to run after delay milliseconds (pausing when delay is null), always invoking the latest callback reference and exposing reset and clear controls.

Installation

pnpm dlx shadcn@latest add https://ohooks.vercel.app/r/useTimeout.json

Usage

Examples

Auto-Dismissing a Toast Banner

Hide a notification banner automatically after 4 seconds, or let the user cancel or restart the timer manually.

Conditional Delayed Execution

Pass null as the delay until a condition is met to defer scheduling the timeout.