react
lifecycle_error
ai_generated
true
Warning: Can't perform a React state update on an unmounted component.
ID: react/react-cannot-update-unmounted
89%Fix Rate
92%Confidence
220Evidence
2020-06-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 18 | active | — | — | — |
Root Cause
Async operation (fetch, timer, subscription) completes after component unmounts and tries to call setState. Warning removed in React 18.3+ but the memory leak remains.
genericWorkarounds
-
93% success Use AbortController in useEffect cleanup to cancel fetch requests on unmount
useEffect(() => { const controller = new AbortController(); fetch(url, { signal: controller.signal }).then(...); return () => controller.abort(); }, [url]);Sources: https://react.dev/reference/react/useEffect#fetching-data-with-effects
-
91% success Clear timers and unsubscribe in the useEffect cleanup function
useEffect(() => { const id = setInterval(fn, 1000); return () => clearInterval(id); }, []);
Dead Ends
Common approaches that don't work:
-
Use an isMounted ref flag to guard setState calls
55% fail
This is an anti-pattern that masks the real issue; the async operation still runs and wastes resources. React docs explicitly discourage this.
-
Ignore the warning since React 18.3+ removed it
70% fail
The warning is gone but the underlying memory leak and wasted network requests remain
Error Chain
Preceded by:
Frequently confused with: