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

88
Visualizações
Calling 2 curried functions onChange

I have a checkbox which calls a curried function and works fine when changing the checkstate as below

const FirstCurriedFunc = (id) => () => {
  //does something
}

return (
   <input type="checkbox" checked={true} onChange={FirstCurriedFunc(id)} />
)

However when I try to call two curried Functions onChange neither function executes as expected even though they both work when called individually as above.

const SecondCurriedFunc = (id) => () => {
  //does something
}

const BothCurriedFuncs = (id) => () => {
  FirstCurriedFunc(id);
  SecondCurriedFunc(id);
}

return (
    <input type="checkbox" onChange={BothCurriedFuncs(id)} />  // neither function executes
);

Can anyone explain why this is/provide a way to call both functions onChange?

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

0

You have to actually invoke both functions in BothCurriedFuncs:

const BothCurriedFuncs = (id) => () => {
    FirstCurriedFunc(id)();
    SecondCurriedFunc(id)();
}

or, maybe cleaner, use a helper function to create a composition:

let compose = (...fns) => () => fns.reduceRight((x, f) => f(x), null)


const BothCurriedFuncs = (id) => compose(SecondCurriedFunc(id), FirstCurriedFunc(id))
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