I've been migrating one of my apps to ES6 on node/react and I have a question about how props are passed down to children. I read a bunch of posts and some address this while others don't. Basically, what I've seen so far is this:
export default class SomeComponent extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<div>
{this.props.text} <<< Props used here
</div>
);
}
}
but I've been able 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 the parentheses for my constructor and the super call? or can I leave my code the way it is
You don't need to pass props to super unless you want to use this.props in constructor.
https://stackoverflow.com/a/34995257/3238350
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With