0

If I run the example below in React, this = undefined and event.currentTarget = null.

How do I get the element the event was bound to?

  <div onMouseEnter={(event) => console.log(event.target)}>
    <span>HELLO</span>
  </div>
Obiwahn
  • 2,677
  • 2
  • 26
  • 36
  • 1
    You might see `null` on the console because the console output is not exactly synchrous, and older React uses [event pooling](https://reactjs.org/docs/legacy-event-pooling.html), which nullifies all event properties. Which react framework version are you using? – Martin Nov 25 '21 at 19:14
  • @Martin That was exactly the problem. I just logged the whole event object and then it is null. – Obiwahn Nov 26 '21 at 08:33

0 Answers0