React Core & Hooks (407 Qs)•Part 9: React Hooks Deep Dive (262 - 316)
What is the difference between super() and super(props) in React using ES6 classes?
junior LevelCode ExampleComponentsHooks
When you want to access this.props in constructor() then you should pass props to super() method.
ruby
**Using `super(props)`:**
javascript
class MyComponent extends React.Component {
constructor(props) {
super(props);
console.log(this.props); // { name: 'John', ... }
}
}
ruby
**Using `super()`:**
javascript
class MyComponent extends React.Component {
constructor(props) {
super();
console.log(this.props); // undefined
}
}
scss
Outside `constructor()` both will display same value for `this.props`.