Skip to content

Instantly share code, notes, and snippets.

@sestok
Created April 17, 2022 19:20
Show Gist options
  • Save sestok/60161feb50b216078d18f7a4b852be6b to your computer and use it in GitHub Desktop.
Save sestok/60161feb50b216078d18f7a4b852be6b to your computer and use it in GitHub Desktop.
Avoid [Memory Leaks] in React by removing Listerners when unmounting components
useEffect(() => {
window.addEventListener("scroll", handleKeyUp);
return () => {
window.removeEventListener("scroll", handleKeyUp);
}
}, []);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment