我们都知道在React中需要绑定函数才能让它正常工作。我知道为什么需要绑定它。
但我不确定为什么我们不需要绑定箭头函数。
例如: 使用箭头函数(无需绑定)
handleClick = () => {
this.setState({
isToggleOn: !this.state.isToggleOn
});
现在,使用函数(需要绑定Bind)
this.handleClick = this.handleClick.bind(this);
handleClick() {
this.setState({
isToggleOn: !this.state.isToggleOn
});
};
我不是在问为什么我们需要在函数中使用bind。我只想知道为什么箭头函数不需要绑定。
谢谢。