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

111
Views
Reacciona la función de flecha al curry en los controladores de eventos

¿Cómo sabe reaccionar para proporcionar el evento como un segundo argumento en el siguiente código?

 const clickMe = (parameter) => (event) => { event.preventDefault(); // Do something } <button onClick={clickMe(someParameter)} />

¿Genera esto para:

 <button onClick={(event) => clickMe(someParameter)(event)} />

¿O cómo funciona? Gracias.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Tal vez esto ayude a explicarlo un poco mejor.

Los cierres son funciones que llevan consigo la información (variables, etc.) de su entorno local cuando se devuelven.

Trabajaré este ejemplo sin funciones de flecha, ya que pueden ser un poco engañosas.

 // `multplyBy` accepts a number as its argument // It returns a new function that "remembers" that number // when it's returned. But that new function *also* // accepts a number function multiplyBy(n) { return function(n2) { return n2 * n; } } // So `multiplyBy(5)` returns a new function // which we assign to the variable `five` const five = multiplyBy(5); // And when we call `five` with a number we get // the result of calling 5 * 10. console.log(five(10));

Si sustituye multiplyBy(n) con clickMe(n) , verá que obtendrá una nueva función que utiliza el oyente de clics, y el primer argumento de esa función siempre será el evento.

about 4 years ago · Juan Pablo Isaza Report

0

La variable Clickme en su código es una función cuyo retorno es la función e => {...}. Entonces, cuando especificas así:

 <button onClick={clickMe(someParameter)} />

es equivalente a

 <button onClick={e => {...} />

que es la forma básica de un controlador de eventos en reaccionar

about 4 years ago · Juan Pablo Isaza 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!