I am in the lesson “React Part II, Components Interacting” of the Front-End Engineer Career Path.
I have noticed in the example codes that the “state” parameter was not included in the constructor call but still used to define a state object.
class Example extends React.Component {
constructor(props) {
super(props);
this.state = { mood: 'decent' };
}
When I review a general JS ES6 Classes document here, however, all the parameters for the subclass (ColorPoint below) constructor are listed in the parentheses.
class Point {
constructor(x, y) {
this.x = x;
this.y = y;
}
}
class ColorPoint extends Point {
constructor(x, y, color) {
super(x, y);
this.color = color;
}
}
My question is, in the first code, how can we use ‘state’ parameter without including in the constructor?
Thank you.