Stop Rebuilding UI

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.

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.

React useIsMounted Hook preview

Scroll to load preview

Installation

FAQ

Was this page helpful?

Sign in to leave feedback.