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
Installation
Related 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.