Currying functions as handlers onClick

(Sagiv Ben Giat) #1

I was thinking about a new approach (new to me) with event handlers like onClick.
If one really wants to pass parameters to a an onClick event handler most tutorials shows a function invocation like this:
onClick={()=>this.myHandler("my param")}

This is bad as it will create a new function instance on each render.
I was thinking about another approach, when your handler is a currying function:

myHandler = myParam => e => { // param is the argument you passed to the function // e is the event object that returned }

onClick={this.myHandler("my param")}

What do you think about this pattern?

Full Example: