today I tried to pass the setState
function to a util function and got a different result on how to pass it. I would like to know why exactly this makes a different.
I have a method like this:
function handleChange(setState) {
setState(oldState => { ... oldState, ... someNewAttributes}
}
It gives me an error ("TypeError: Cannot read property 'updater' of undefined") when I try to pass it like this:
handleChange(this.setState);
But works like a charm if I pass it wrapped in a lamba:
handleChange((x) => this.setState(x));
Can someone explain this with the Javascipt mechanics, why this makes a difference?