You need to pass props in super only if you want to access this.props in constructor of the class.
class Base extends React.Component {
constructor(props) {
console.log('Base', props);
}
render() {
return <div>Base {this.props.name}</div>;
}
}
class Sub extends Base {
constructor(props) {
super({
name: 'New name prop'
});
console.log('Sub', arguments);
}
}
var sub = <Sub name="Gomic" />
React.render(sub, document.getElementById('container'));
Props are by default not assigned in the constructor. They are assinged in the method React.createElement. So super(props)
should be called only when the superclass's constructor manually assings props
to this.props
. When you just extend the React.Component
calling super(props)
method will do nothing with props
.
Reference:
https://discuss.reactjs.org/t/should-we-include-the-props-parameter-to-class-constructors-when-declaring-components-using-es6-classes/2781/2