If I attached event listener to a component, do I need to explicitly to remove it when it's unmounted?
For e.g.
componentRef = React.createRef();
handleWheel = (e) => {
e.preventDefault();
}
componentDidMount() {
if (this.componentRef.current) {
this.componentRef.current.addEventListener('wheel', this.handleWheel);
}
}
componentWillUnmount() {
if (this.componentRef.current) {
this.componentRef.current.removeEventListener('wheel', this.handleWheel);
}
}
render() {
<Container ref={this.componentRef}>...</Container>
}
So I wonder if componentWillUnmount
is required in this case