Shadcn.io is not affiliated with official shadcn/ui
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
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 projectRelated Components
React useIsClient Hook
Check if running on client
React useUnmount Hook
Run cleanup on unmount
React useTimeout Hook
Declarative setTimeout management
React useInterval Hook
Declarative setInterval management
React useEventCallback Hook
Stable callback reference
React useDebounceCallback Hook
Debounce function calls
FAQ
Was this page helpful?
Sign in to leave feedback.