function clickMe(e){ //e is the event } <button onClick={this.clickMe}></button> function clickMe(parameter){ //how to get the "e" ? } <button onClick={() => this.clickMe(someparameter)}></button> Quiero recibir el event . ¿Cómo puedo obtenerlo?
Prueba esto:
<button onClick={(e) => { this.clickMe(e, someParameter); }} > Click Me! </button>Y en su función:
function clickMe(event, someParameter){ //do with event }Con el ES6, puede hacerlo de una manera más corta como esta:
const clickMe = (parameter) => (event) => { // Do something }Y úsalo:
<button onClick={clickMe(someParameter)} />Solución 1
function clickMe(parameter, event){ } <button onClick={(event) => {this.clickMe(someparameter, event)}></button>Solución 2 El uso de la función de enlace se considera mejor que la función de flecha, en la solución 1. Tenga en cuenta que el parámetro del evento debe ser el último parámetro en la función del controlador
function clickMe(parameter, event){ } <button onClick={this.clickMe.bind(this, someParameter)}></button>