Make your AI a shadcn expert

React useIsMounted Hook

React useIsMounted hook returns a function to check if component is still mounted. Prevents state updates on unmounted components.

React useIsMounted Hook preview

Scroll to load preview

Avoid the "setState on unmounted component" warning in React. useIsMounted returns a stable function that returns true while mounted, false after unmount. Call it before setting state in async callbacks, fetch handlers, or setTimeout. The function reference never changes—safe to use in dependency arrays. Uses useRef internally for synchronous updates on unmount. Perfect for data fetching, animations, or any async operation that might complete after unmount. Works with Next.js App Router, React 18 Strict Mode, and any async pattern.

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

FAQ

Was this page helpful?

Sign in to leave feedback.