为什么只需要对基于类的组件使用this.props?

时间:2019-07-06 18:58:06

标签: reactjs

类组件和函数组件都是函数,那么为什么要使用this关键字才能使用props?

2 个答案:

答案 0 :(得分:1)

有区别。类使用严格模式,在这种模式下,将其设置为undefined而不是绑定到全局范围。

在此处了解更多信息: https://blog.kiprosh.com/understanding-this-keyword-in-javascript-and-react/

答案 1 :(得分:0)

Dan Abramov从反应的角度在他的个人博客中解释了这个主题。

看看它:https://overreacted.io/how-does-react-tell-a-class-from-a-function/