I have a web application that page A has video, and page B doesn't. The video has the onended event when it finishes video playback. I tried to remove the event before the component unmounts with removeEventListener, or the video ended event will be fired after I switched to page B.
However, I cannot find the proper way to remove callback with parameters. I used the arrow function and bind to pass parameters, but these two methods made event removal impossible.
componentDidMount() {
// 1st trial: anonymous function cannot be removed
this.video.onended = () => this.videoOnEndedCallback(params);
// 2nd trial: bind() creates new function, cannot be referenced either
this.video.onended = this.videoOnEndedCallback.bind(this, params);
}
componentWillUnmount() {
this.video.removeEventListener('ended', this.videoOnEndedCallback);
}
Lastly, I set the onended to null, and it works.
componentWillUnmount() {
this.video.onended = null;
}
Question
If setting onended to null equals the effect of removeEventListener?
If not, is there any other proper way to remove callback with parameters?