+ 1

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?

19th Dec 2020, 2:53 PM
Shehroz Irfan
Shehroz Irfan - avatar
2 Answers
+ 4
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. https://code.sololearn.com/c9WC1kop2ETI/?ref=app
19th Dec 2020, 3:36 PM
Avinesh
Avinesh - avatar
+ 3
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.
19th Dec 2020, 4:11 PM
Raj Chhatrala
Raj Chhatrala - avatar