class Foo extends Component {
constructor(props) {
super(props);
this.handleClick = this.handleClick.bind(this);
}
handleClick() {
console.log('Click happened');
}
render() {
return <button onClick={this.handleClick}>Click Me</button>;
}
}
i tried to remove this code
this.handleClick = this.handleClick.bind(this);
but there's no problem, still works. Can you give me some examples that illustrate of what bind does in reactjs context (like in the first code), like if you remove this bind code, will results in error