Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

120
Visualizações
React curried arrow function in event handlers

How does react know to provide the event as a second argument in the code below?

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

Does it generate this to:

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

Or how does it work? Thanks.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Maybe this will help explain it a little better.

Closures are functions that carry the information (variables etc.) from their local environment with them when they're returned.

I'll work this example without arrow functions as they can be a little deceiving.

// `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));

If you substitute multiplyBy(n) with clickMe(n) you'll see that you'll get a new function that gets used by the click listener, and the first argument of that function will always be the event.

about 4 years ago · Juan Pablo Isaza Relatório

0

Clickme variable in your code is a function which has return is function e => {...}. So when you specify like this:

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

it is equivalent to

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

which is basic form of a event handler in react

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda