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>

const App = () => (
      <div onMouseEnter={(event) => console.log(event.currentTarget)}>
        <span>HELLO</span>
      </div>
);

ReactDOM.render(<App />, document.querySelector('.react'));
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<div class='react'></div>
CertainPerformance
  • 356,069
  • 52
  • 309
  • 320
Obiwahn
  • 2,677
  • 2
  • 26
  • 36

0 Answers0