Why does react class component always need to call super(props) in its constructor?
Although it is suggested to pass props to
super
but it isn't strictly necessary.
Passing it just helps in an odd situation where you might have a called a method in constructor and then at some point of time in future decided to use props in it. Now since props aren't available in the constructor since you haven't passed props to super
, it would result in an error. This kind of situation might be tricky to debug and hence its recommended to pass props always whenever you write a constructor so that it ensures this.props
is set even before the constructor exits.