I had higher order component in react like this:
export default function (InnerComponent) {
class InfiniteScrolling extends React.Component {
co
.bind
always creates a new function so you need to do like below, so it adds and removes the same function.
constructor(props){
super(props);
this.onScroll = this.onScroll.bind(this); //bind function once
}
componentDidMount() {
window.addEventListener('scroll', this.onScroll, false);
}
componentWillUnmount() {
// you need to unbind the same listener that was binded.
window.removeEventListener('scroll', this.onScroll, false);
}