Description
Adding a useEffect with an empty clean up callback prevents async "state update after unmount" warning in certain cases.
React version: 17.0.2
Steps To Reproduce
- In the example provided
- Trigger the async request by clicking the Load button
- Navigate away before request resolves
Link to code example:
https://codesandbox.io/s/spring-frog-9n59kj?file=/src/LoaderPage.jsx
The current behavior
In React 17.0.2 adding a useEffect with empty clean up callback prevents the "state update on an unmounted component" warning
The expected behavior
In React 16, the warning is shown unless the clean up call back does work, for example by updating a guard "instance variable" in the vain of the "isMounted" scenario (as in https://stackoverflow.com/a/60907638).
I am not clear on what the current intention is, given #17925 and the fact that in 18.0.0-rc2 the state update is not performed after unmount in this example, with or without the empty destroy function.
Activity
cdscawd commentedon Mar 11, 2022
Fuck USA