一、使用class的实例方法
class Hello extends React.Component {
onIncrement = () => {
this.setState({
count: this.state.count + 1
})
}
}
二、箭头函数
<button onClick={() => this.onIncrement()}>+1</button>
三、bind
class Hello extends React.Component {
constructor() {
super()
this.onIncrement = this.onIncrement.bind(this)
}
}