2022-07-12 15:42:08 +01:00
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- javascript
|
|
|
|
- react
|
|
|
|
---
|
|
|
|
|
|
|
|
# Errors
|
|
|
|
|
|
|
|
## State update on unmounted component
|
|
|
|
|
2024-02-02 15:58:13 +00:00
|
|
|
> 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.
|
2022-07-12 15:42:08 +01:00
|
|
|
|
2024-02-02 15:58:13 +00:00
|
|
|
This typically happens when you have an API request running in the background.
|
|
|
|
Once the data is returned, React tries to update the state but the component is
|
|
|
|
unmounted.
|
2022-07-12 15:42:08 +01:00
|
|
|
|
2024-02-02 15:58:13 +00:00
|
|
|
As the warning suggests, this can be resolved using the cleanup parameter within
|
2024-06-15 11:30:03 +01:00
|
|
|
[React_useEffect](React_useEffect.md#cleanup-functions).
|