React,为什么在 ES6 class 构造函数中使用 super(props)?

React, why use super(props) inside of ES6 class constructor?

我意识到 super 关键字可以用来调用父组件中的函数。但是,我不完全清楚为什么要在下面的示例中使用 super 关键字——只是将传递给构造函数的任何道具传递给它。

有人可以阐明在 ES6 class 构造函数中使用 super 关键字的各种原因吗?

  constructor(props) {
    super(props);

    this.state = {
      course: Object.assign({}, this.props.course),
      errors: {   }
    };

    this.updateCourseState = this.updateCourseState.bind(this);
  }

super 允许您访问父class 的构造方法。包含道具的唯一原因是在构造函数中访问 this.props。