# Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.

- **ID:** `react/setstate-on-unmounted-component-with-async`
- **Domain:** react
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

An async operation (e.g., fetch, timeout) completes after the component has unmounted, and the callback attempts to set state on the unmounted component.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| React 18.2.0 | active | — | — |
| React 19.0.0 | active | — | — |
| React 16.14.0 | active | — | — |

## Workarounds

1. **Use an AbortController with fetch and call abort() in the useEffect cleanup: `const controller = new AbortController(); useEffect(() => { fetch(url, { signal: controller.signal }); return () => controller.abort(); }, []);`** (90% success)
   ```
   Use an AbortController with fetch and call abort() in the useEffect cleanup: `const controller = new AbortController(); useEffect(() => { fetch(url, { signal: controller.signal }); return () => controller.abort(); }, []);`
   ```
2. **For timeouts, use clearTimeout in cleanup: `useEffect(() => { const timer = setTimeout(() => setState(...), 1000); return () => clearTimeout(timer); }, []);`** (95% success)
   ```
   For timeouts, use clearTimeout in cleanup: `useEffect(() => { const timer = setTimeout(() => setState(...), 1000); return () => clearTimeout(timer); }, []);`
   ```
3. **Use a library like `use-http` or `react-query` that handles cancellation automatically.** (85% success)
   ```
   Use a library like `use-http` or `react-query` that handles cancellation automatically.
   ```

## Dead Ends

- **** — The async task still executes, wasting resources; React recommends cleanup instead. (90% fail)
- **** — It can lead to memory leaks and unpredictable behavior in production, especially with frequent mount/unmount cycles. (95% fail)
