Curried functions gets cached by the compiler (some guy)
This component below has two buttons, one calls a function which returns the onClick handler, the other does the same, but inline.
According to my knowledge, both are doing the same thing, they are creating a new function () => this.foo()
on each render()
call. Someone said that the curried function version is cached and optimized by the compiler, so there is a benefit compared to the inline version. I think its the exact same thing and the guy who wrote this wanted to conceal an inline function with that expression.
class MyComponent extends Component {
foo = () => console.log('fooo')
getFunction = callback => {
return () => callback();
}
render() {
return <div>
<button onClick={this.getFunction(this.foo)}>curried function</button>
<button onClick={() => this.foo()}>inline function</button>
</div>
}
}
I did some googling, but could't find a proof/disproof to the statement, what do you think guys?