Make your AI a shadcn expert

React useTimeout Hook

React useTimeout hook for declarative setTimeout with auto-cleanup. Pass null to pause, callback refs for fresh state. TypeScript ready.

React useTimeout Hook preview

Scroll to load preview

Schedule delayed callbacks the React way with useTimeout. Pass a callback and delay—the timeout runs once and cleans up automatically on unmount. Pass null as delay to pause or disable the timeout. Callback is stored in a ref so it always has access to fresh props/state without resetting the timer. Timer restarts when delay changes. Cleanup happens automatically on unmount or when delay becomes null. No memory leaks, no stale closures. Perfect for delayed UI updates, auto-dismiss notifications, debounced actions, redirect timers, or any one-shot delayed operation. SSR safe, works with Next.js.

Install with AI

If you've connected the shadcn.io MCP server to Claude Code, Cursor, Windsurf, or any MCP-ready AI editor, prompt your agent to install this hook for you — no copy-paste, no CLI:

use shadcnio to install the use-timeout hook into my project

FAQ

Was this page helpful?

Sign in to leave feedback.