Touchpad Touchpad - 2 months ago 26
React JSX Question

finding mouse target in react

I'm trying to add a simple mouse-click tracking to later on complicate it a bit more however I've sort of hit a road block, the code below console logs:

when I click the div and I can't understand why or how to get the div I click on to "become" the target

import React, { Component } from 'react';

class MySuperClass extends Component {

_setPosition (e) {
render () {
return (
<div className='a-class' onMouseDown={() => this._setPosition(event)}>&nbsp;</div>

export default MySuperClass;


You have to pass the DOM event.

<div className='a-class' onMouseDown={event => this._setPosition(event)}>&nbsp;</div>

Or you can simply do this:

<div className='a-class' onMouseDown={this._setPosition}>&nbsp;</div>