I find currying is handy when I'll eventually need access to a value that isn't quite in scope/not available yet.
My most recent use case was when I needed an on click handler. I needed to be able to reset my form and do other stuff on a button click, but the reset form function wasn't available until the form rendered.
So I just created a function that takes the reset form and returns an on click listener. I found it a nice way to keep things tidy and near the other relevant stuff in scope.
Here is the React snippet:
constdoStuffOnClick=(resetForm:(nextState?:any)=>void)=>()=>{// do stuff// ............resetForm({values:someValue,});};return(<><Formik>{({resetForm,})=>(<><ButtononClick={doStuffOnClick(resetForm)}>
Do Stuff
</Button></>)}</Formik></>
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I find currying is handy when I'll eventually need access to a value that isn't quite in scope/not available yet.
My most recent use case was when I needed an on click handler. I needed to be able to reset my form and do other stuff on a button click, but the reset form function wasn't available until the form rendered.
So I just created a function that takes the reset form and returns an on click listener. I found it a nice way to keep things tidy and near the other relevant stuff in scope.
Here is the React snippet: