ES6本质

来源:3-5 添加交互行为

纯情掉了一地

2019-10-04

extends Component
组件都继承父组件 Component
this.state 也就是 Component.prototype.state 对吗?

写回答

1回答

艾特老干部

2019-10-08

你这样理解是不对的。如果this.state 是 Component.prototype.state,那么所有组件都会共享这个state,显然是不对的。可以这样理解,state是Component的一个实例属性,这样extends Component后,每一个具体的组件都会有state属性:

function Component(props) {

    this.state = {};

    //...

}

0
3
艾特老干部
回复
纯情掉了一地
你这种写法我没有用过,不确定。
2019-10-10
共3条回复

React16+Redux实战企业级大众点评Web App

从架构设计到部署上线,带你学习React技术栈与核心思想

1071 学习 · 306 问题

查看课程