Patrick Duncan
Patrick Duncan

Reputation: 559

Accessing props of React events

https://facebook.github.io/react/docs/events.html

I'm using the onMouseOver and onMouseOUt events.

...
mouseOver(e) {
  this.setState({hover: true});
}

mouseOut(e) {
  this.setState({hover: false});
}

render() {
...
<NavItem
  onMouseOver={this.mouseOver.bind(this)}
  onMouseOut={this.mouseOut.bind(this)}
  eventKey={0} href='#'
</NavItem>
 ...

How would I access/set the props of the 2 events, a property like screenX

Upvotes: 0

Views: 78

Answers (1)

Rico Herwig
Rico Herwig

Reputation: 1712

You can access the properties of the event, just like in vanilla JavaScript.

mouseOver(e) {
  const screenX = e.screenX;
  this.setState({hover: true});
}

Note: if you want to access the event asynchronously, you would call e.persist() at the beginning of your event handler.

Upvotes: 1

Related Questions