React onClick - pass event with parameter

IMOBAMA picture IMOBAMA · Mar 4, 2017 · Viewed 79.1k times · Source

Without Parameter

function clickMe(e){
  //e is the event
}

<button onClick={this.clickMe}></button>

With Parameter

function clickMe(parameter){
  //how to get the "e" ?
}
<button onClick={() => this.clickMe(someparameter)}></button>

I want to get the event. How can I get it?

Answer

Jyothi Babu Araja picture Jyothi Babu Araja · Mar 4, 2017

Try this:

<button onClick={(e) => {
     this.clickMe(e, someParameter)
}}>Click Me!</button>

And in your function:

function clickMe(event, someParameter){
     //do with event
}