I'm trying to learn react.
The documentation for react says to pass constructor arguments as follows.
class Clock extends React.Component {
constructor(props) {
super(props);
this.state = {date: new Date()};
}
render() {
This post says the reason to reference super in that function is you might need to have props in super() if you want to access this.props in the constructor.
But - if you don't need to do that, and you just need to initialise state, do you still need the super() line?
I have seen a lot of tutorials that define it as follows:
class Basic extends React.Component {
state = {
selectedValue: null,
createdAt: null
};
I can't find a reference to why this is acceptable. Do you need super, even if you don't need props in the constructor?