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

Let’s get started,

When you want to access this.props in constructor() then you should pass props to super() method.

class MyComponent extends React.Component {
constructor(props) {
super(props)
console.log(this.props) // { name: 'John', ... }
}
}
class MyComponent extends React.Component {
constructor(props) {
super()
console.log(this.props) // undefined
}
}

Summary

Keep learning, keep growing!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sonika | Working at Walmart | startlearncoding.com

Sonika | Working at Walmart | startlearncoding.com

Working in Walmart as Senior UI Developer | React | JavaScript | Data Structure