0

This sentence is supposed to explain why super(props) is needed:

"This is because it will allow us to call the constructor of the parent class and initialize itself in case our class extends any other class which has constructor itself."

Can anyone explain this in a way that makes sense? What does it mean for one class to extend another?

  • 1
    Possible duplicate of [What is super(props) doing for my React component?](https://stackoverflow.com/questions/41837992/what-is-superprops-doing-for-my-react-component) – maazadeeb May 06 '19 at 04:28

1 Answers1

0

They're referring to the traditional OOP reason for calling super, which is to call the constructor of the parent class your current one is extending. Your class components will extend React's classes, such as Component or PureComponent.

If you're wondering about super(props)'s place in React specifically, check out the accepted answer in this post.

There's also posts explaining difference between super() and super(props) which you can Google around for.

P.S. Official React docs say to always use super(props) in a constructor.

Jayce444
  • 8,725
  • 3
  • 27
  • 43