Skip to content
doubtly

2 answers

In a React class component, super(props) calls the constructor of the parent class React.Component; it must be called before this can be used in the constructor.

class Welcome extends React.Component {
  constructor(props) {
    super(props);              // call React.Component's constructor
    this.state = { count: 0 }; // 'this' can be used only after super()
    console.log(this.props.name);
  }
  render() { return <h1>Hello {this.props.name}</h1>; }
}
  • In JavaScript, a subclass constructor must call super() before using this, otherwise it throws a ReferenceError.
  • Passing props to super(props) sets this.props inside the constructor.
  • super can also call a parent method, e.g. super.someMethod().

Function components do not use super.

Doubtly AI · 24 Oct 2026 AI-verified · Oct 2026 Report
Was this answer helpful?

Your answer

Log in or create a free account to answer this question.