Es6 reacts to receiving props in a child component

I ported one of my applications to ES6 on node / react, and I have a question about how props are passed on to children. I read a bunch of posts, and some addresses are, others are not. Basically, what I have seen so far is:

export default class SomeComponent extends React.Component { constructor(props) { super(props); } render() { return ( <div> {this.props.text} <<< Props used here </div> ); } } 

but I managed to get my component to work with the following:

 export default class SomeComponent extends React.Component { constructor() { super(); <<< notice no props in parentheses } render() { return ( <div> {this.props.text} <<< Props used here </div> ); } } 

Is there a reason why I should pass the props in parentheses to my constructor and super call? or I can leave my code as it is.

+6
source share
2 answers

You need to pass the props because you are expanding from React.Component, otherwise you will not be allowed to access this.props in the constructor.

This is a kind of composition template.

0
source

You do not need to pass super details if you do not want to use this.props in the constructor.

fooobar.com/questions/30992 / ...

+1
source

All Articles