Today I learned:
React 18 intentionally mounts, unmounts, and remounts components, but only in development mode when is enabled. This behavior ensures effects are properly cleaned up and re-synchronized, simulating real-world scenarios like navigating away and back to a page. With this behavior, it forces developers to implement proper cleanup functions in useEffect hooks.
In other words, it helps developers to think about idempotent effects.
Relevant documents:
https://react.dev/blog/2022/03/29/react-v18
Top comments (0)