class MyButton extends Component {
state = { tapped: false }
tap() {
this.setState({ tapped: true }); // --> 'this' here is undefined
}
render() {
return (
<button onClick={ this.tap }>TAP ME</button>
)
}
}
I know with ES6 class React doesn't auto bind this to component's instance, hence inside tap "this" is undefined. What I don't understand here is why tap function is present in the component's instance and is not throwing an error undefined of tap doesn't exist? How tap is part of component instance?