DEV Community

Discussion on: A UseDarkMode react hook for everyone!

Collapse
 
bryce profile image
Bryce Dorn

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.

Thread Thread
 
willholmes profile image
Will Holmes

Thanks for the suggestion Bryce, this has been added in the latest version 1.0.2

Thread Thread
 
raaynaldo profile image
Raynaldo Sutisna

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