1class Counter extends React.Component {
2 constructor(props) {
3 super(props);
4
5 this.state = {
6 count : 1
7 };
8
9 this.delta = this.delta.bind(this);
10 }
11
12 delta() {
13 this.setState({
14 count : this.state.count++
15 });
16 }
17
18 render() {
19 return (
20 <div>
21 <h1>{this.state.count}</h1>
22 <button onClick={this.delta}>+</button>
23 </div>
24 );
25 }
26}
1// way #1 - recommended
2// puting .bind(this) after using the reference
3
4 <input onChange={this.onInputChange.bind(this)} placeholder="First Name" />
5
6// way #2
7// adding this line for each method you use
8
9 constructor(){
10 this.onInputChange = this.onInputChange.bind(this)
11 }
12