Currying in react.js | Sololearn: Learn to code for FREE!


Currying in react.js

I have a function : const changeHandle = input => e => { // set the state } But I am confused how it is working? anyone can explain in simple words?

12/19/2020 2:53:21 PM

Shehroz Irfan

2 Answers

New Answer


From what I know curried function basically takes an argument and returns a function. The returned function can again be called to do some processing. In your case changeHandle is a function which returns another function. This is an example.


It's like you have a function that returns an anonymous function. If you have list of users and you want to pass id to a function and call it on click or any event like that, then you will have to have an anonymous function passed as reference to event attribute and that function calls another function with parameters needed. Like: <button onClick={() => someFunc(value, value)} ></button> But if you want to avoid that ugly looking syntax what you can do is what you asked about. You have a function that returns another function.