我很困惑,我们说react js具有单向流,这意味着道具只能从父级发送到子级。但是为什么我们要写super(props); ??
通常我们写
class Test extends React.Component {
constructor(props)
{
super(props);
this.state = { hello : "World!" };
}
}
那我们为什么要从孩子向父母发送道具? 我希望我的问题得到解释
答案 0 :(得分:1)
但是为什么我们要编写super(props);
这与组件的父/子关系无关。这与React.Component
和class Test extends React.Component
之间的超类/子类关系有关。 super(props)
调用React.Component构造函数,并传递道具。