1

I've seen tow cases set default state like:

class Page extends Component {
  state = {
    page: 0,
  };
}

vs

class Page extends Component {
  constructor(props) {
    super(props);
    this.state = { page: 0 };
  }
}

Use first variant Is it bad practice? Where can i find out more information about it? Or how this ecmascript's feature is named?

Shubham Khatri
  • 270,417
  • 55
  • 406
  • 400
platypussss
  • 159
  • 8

1 Answers1

1

You can use the first variant if you have stage-2 preset configured with babel. It is a class property syntax and is not event included in ES7 proposal, however it is available as stage-2 preset with babel. However using the first or the second variant is a matter of preference. They both transpile to the exact same thing.

First method:

Second method

Shubham Khatri
  • 270,417
  • 55
  • 406
  • 400