AaronCCWong / react-card-flip

React component for card flipping animation.
https://aaronccwong.github.io/react-card-flip
MIT License
337 stars 64 forks source link

Added useEffect cleanup function #93

Closed petrosDemetrakopoulos closed 2 years ago

petrosDemetrakopoulos commented 2 years ago

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

AaronCCWong commented 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.

petrosDemetrakopoulos commented 2 years ago

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.

AaronCCWong commented 2 years ago

Please open an issue with the error or an example that reproduces the issue.