10-构造函数加不加props

加与不加props的区别究竟在哪里呢?

以下来自stackoverflow的解释:

What’s the difference between “super()” and “super(props)” in React when using es6 classes?

不加props

1
2
3
4
constructor(props) {
super();
console.log(this.props) //undefined
}

props

1
2
3
4
constructor(props) {
super(props);
console.log(this.props) //props will get logged.
}