Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React bind and keep access to event object?

On Facebook's React tips page Communicate Between Components they show an example using javascript's bind() to pass arguments to the parent's handleClick() method.

This works well, except using bind the first argument of an event handler is no longer the event that was triggered. I'd still like access to the event so what are my options in this regard?

like image 726
Sgraffite Avatar asked Oct 20 '22 04:10

Sgraffite


1 Answers

You just specify it as

onClick={e => this.handleClick(e, i)}

That way you create a new anonymous function that both passes the original event and your custom data.

like image 190
zerkms Avatar answered Oct 21 '22 22:10

zerkms