Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

137
Views
Reaccionar onClick - pasar evento con parámetro

sin parámetro

 function clickMe(e){ //e is the event } <button onClick={this.clickMe}></button>

con parámetro

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

Quiero recibir el event . ¿Cómo puedo obtenerlo?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Prueba esto:

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

Y en su función:

 function clickMe(event, someParameter){ //do with event }
over 4 years ago · Santiago Trujillo Report

0

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)} />
over 4 years ago · Santiago Trujillo Report

0

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>
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!