InterviewHubPRO
Section Overview
Q389

Question 389 of 445

Part 11: Legacy Architecture, Migration Patterns & Historical Internals (354 - 445)

87%
React & Modern Frontend (445 Qs)•Part 11: Legacy Architecture, Migration Patterns & Historical Internals (354 - 445)

What is the difference between super() and super(props) in React using ES6 classes?

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`.