componentDidMount() {
window.addEventListener("scroll", (e) => {console.log("Hello"});
}
componentWillUnmount() {
window.removeEventListener("scroll", (e) => {console.log("Hello"});
}
...do I really need to do window.removeEventListener("scroll", (e) => {console.log("Hello")});
?
Or can I just do window.removeEventListener("scroll", ()=> {});
(with an empty function)? I don't understand why, when removing the eventListener, I need to pass it the exact same anonymous function?
what if I do window.removeEventListener("scroll", ()=> {console.log("Hello2")});
- is this considered a new function now? So will this not remove the original event listener (which has console.log("Hello");
) ?