-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Closed
Description
INCORRECT
class MyComponent extends Component {
constructor(props) {
super(props);
this.state = {
counter: props.initialValue
};
}
}CORRECT
class MyComponent extends Component {
state = {
counter: this.props.initialValue
};
}Why?
It may reduce boilerplate by not having to define a constructor just for initializing the state.
What do you think about this?
iegik, MrHen, levithomason, velusgautam and fedorovsky