Why you don't pass an event parameter in addEventListener callback function

I reached the challenge of adding/removing events in componentDidMount and componentWillUnmount, however I got confused with your solution:

  componentDidMount() {
    // Attach an event
    document.addEventListener("keydown", this.handleKeyPress)

  }
  componentWillUnmount() {
    document.removeEventListener("keydown", this.handleKeyPress)

While my solution is :

  componentDidMount() {
    // Attach an event
    document.addEventListener("keydown", event => this.handleKeyPress(event))

  }
  componentWillUnmount() {
    document.removeEventListener("keydown", event => this.handleKeyPress(event))

  }

But it does not pass the test. Why?

This is the challenge url: React Events

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.