Make your AI a shadcn expert

React useInterval Hook

React useInterval hook for declarative setInterval. Pass null to pause, auto-cleanup on unmount. No stale closures. TypeScript ready.

React useInterval Hook preview

Scroll to load preview

Run intervals the React way without setInterval headaches. useInterval takes a callback and delay in milliseconds—pass null to pause. Callback is stored in a ref so it always has access to fresh props and state. No stale closure bugs. Auto-clears on unmount or delay change. Perfect for polling APIs, auto-saving drafts, countdown timers, slideshow carousels, or any periodic task. Declarative start/stop with null delay. SSR safe—interval only runs client-side. Works with Next.js App Router and any React framework.

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-interval hook into my project

FAQ

Was this page helpful?

Sign in to leave feedback.