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

85
Views
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 answers
Answer question

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 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!