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.
Using super(props):
class MyComponent extends React.Component {constructor(props) {super(props);console.log(this.props); // { name: 'John', ... }}}
Using super():
class MyComponent extends React.Component {constructor(props) {super();console.log(this.props); // undefined}}
Outside constructor() both will display same value for this.props.
December 31, 2021
395
Read more
What is React?
November 06, 2022
ReactJSHow to programmatically trigger click event in React?
November 06, 2022
ReactJS