It prevents memory leaks in older browsers; if the hook is rendered and later removed the event listener in some cases will still remain. Garbage collection has improved over the years but browsers like IE haven't received these updates so it's good to manually remove event listeners for consistent behavior.
Oh I see. Thanks Bryce! You were refering to the npm package? I thought you were refering to the code snippet in this blog. Thanks for the explanation. I was wondering why we need cleanup function for hook
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I'm sorry I don't really understand, but I'm curious why we need a cleanup function here?
It prevents memory leaks in older browsers; if the hook is rendered and later removed the event listener in some cases will still remain. Garbage collection has improved over the years but browsers like IE haven't received these updates so it's good to manually remove event listeners for consistent behavior.
Thanks for the suggestion Bryce, this has been added in the latest version 1.0.2
Oh I see. Thanks Bryce! You were refering to the npm package? I thought you were refering to the code snippet in this blog. Thanks for the explanation. I was wondering why we need cleanup function for hook