I can't understand why this.click = this.click.bind(this)
is needed and what is it doing.
class MyComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
name: 'Initial State'
};
this.click = this.click.bind(this);
}
click() {
this.setState({
name: 'React Rocks!'
});
}
render() {
return (
<div>
<button onClick = {this.click}>Click Me</button>
<h1>{this.state.name}</h1>
</div>
);
}
};