react向组件传递函数方式
bind
constructor(props) {
super(props);
this.state = {
value: 0
};
this.handleClick2 = this.handleClick1.bind(this);
}
箭头函数
handleClick3 = () => {
console.log(this);
};
直接传递
handleClick1() {
console.log(this);
}
<button onClick={this.handleClick1}>click 1</button>
<button onClick={this.handleClick2}>click 2</button>
<button onClick={this.handleClick3}>click 3</button>
点击三个按钮输出结果如下图:

react向组件传递函数方式
bind
箭头函数
直接传递
点击三个按钮输出结果如下图:
