Closed petrosDemetrakopoulos closed 2 years ago
This seems redundant. The article makes sense since an async function is being executed so it is possible that the cleanup will run setting mounted
to false
which will cause the chained promise to not execute. However, your change runs synchronously so the cleanup will never run before the code block wrapped within the if (mounted)
check.
OK, any idea on how we could avoid it. Actually in a project of my team, the component caused a leak error mentioned in the browser console, so this is why I tried to fix it. It is not theoretical, it happened.
Please open an issue with the error or an example that reproduces the issue.
This PR implemements a useEffect cleanup function that prevents the creation of memory leaks under certain conditions.
For more information about useEffect cleanup functions you can check this link: https://medium.com/technology-hits/how-to-fix-memory-leak-issue-in-react-js-using-hook-a5ecbf9becf8