【发布时间】:2021-06-17 11:12:04
【问题描述】:
我有一个与此代码相关的问题:https://github.com/reactjs/redux/blob/master/examples/async/containers/App.js
具体来说:
constructor(props) {
super(props)
this.handleChange = this.handleChange.bind(this)
this.handleRefreshClick = this.handleRefreshClick.bind(this)
}
我猜这是一个两部分的问题。
- 为什么我需要将句柄更改设置为
this.handleChange =类的实例,我不能只使用静态函数来处理句柄更改并在onClick={handleRefreshClick}>类中直接调用它吗? - 我不知道这里发生了什么:
this.handleRefreshClick.bind(this)
谢谢
【问题讨论】:
-
不完全是,我不太了解一个类的上下文,尤其是数字 2
-
它不会改变
bind的含义。您使用bind来维护this的范围。在 react 的上下文中,这允许您调用诸如this.setState之类的东西。