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

后端 未结 10 1956
不思量自难忘°
不思量自难忘° 2020-11-22 09:01

When is it important to pass props to super(), and why?

class MyComponent extends React.Component {
  constructor(props) {
    supe         


        
10条回答
  •  情深已故
    2020-11-22 09:40

    As per source code

    function ReactComponent(props, context) {
      this.props = props;
      this.context = context;
    }
    

    you must pass props every time you have props and you don't put them into this.props manually.

提交回复
热议问题