-
Notifications
You must be signed in to change notification settings - Fork 49.1k
Description
When using ES6 classes, autobinding doesn't happen, as we all hopefully know by now :).
So when I do:
<button onClick={this.handleClick}>Test Button</button>
I'd expect that "this" inside of my handleClick
function in my class is undefined. This is, in fact, what happens.
However, when I do:
<input onChange={this.handleChange} type="checkbox" />
..."this" inside of my handleChange
function is the input component's constructor.
Obviously, if I just bind my functions all the time, the problem is resolved. But since "this.setState" exists on the constructor...I was calling this.setState inside my handleChange function, not getting an error, and nothing was happening. So it was confusing to track down.
Admittedly I'm not immediately sure what to do about this...but I thought I'd make an issue and open it up for discussion.