class App extends React.Component {
constructor(props) {
super(props);
this.state = {};
}
// React says we have to define render()
render() {
return <div>Hello world</div>;
}
};
here is only one reason when one needs to pass props to super():
When you want to access this.props in constructor.
class MyComponent extends React.Component {
constructor() {
console.log(this); // Reference Error i.e return undefined
}
render() {
return <div>Hello {this.props.name}</div>;
}
}
Super(): It is used to call the constructor of its parent class.
This is required when we need to access some variables of its parent class.
Props: It is a special keyword that is used in react stands for properties.
Used for passing data from one component to another.
from geeksforgeeks.org