I
I
Igor Shumilovsky2016-04-11 12:15:46
JavaScript
Igor Shumilovsky, 2016-04-11 12:15:46

RemoveEventListener in React and IE. How does it work?

Hello! I have this situation: there is a component that hangs an eventListener on the document in componentDidMount . In componentWillUnmount I remove it. It all works well in browsers, except for IE. Ie first performs the function that I passed when creating the listener, and only then removes it (or does not remove it at all, I did not understand). How to be in that case? What's happening?

componentDidMount() {
    if (this.props.controls) {
      document.addEventListener('click', this.componentSearchListener, false);
      document.addEventListener('touchstart', this.componentSearchListener, false);
    }
  }

 componentWillUnmount() {
    document.removeEventListener('click', this.componentSearchListener, false);
    document.removeEventListener('touchstart', this.componentSearchListener, false);
  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Ninja Mate, 2016-04-11
@JiSeven

Igor Shumilovsky : what if we hang window.removeEventListener and window.addEventListener?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question