Sgraffite
Sgraffite

Reputation: 1928

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?

Upvotes: 5

Views: 411

Answers (1)

zerkms
zerkms

Reputation: 255005

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.

Upvotes: 3

Related Questions