re: Why Do We Use this.setState()? VIEW POST

FULL DISCUSSION
 

Hello!, Great article, thanks for sharing

I am also investigating these matters nowadays and recently discovered that if you have

class Foo extend Component {
  constructor(props){
    super(props)
    this.state = { foo: 1 }
  }
//...

And you are:

  • using modern js or babel
  • not doing extra stuff on the constructor

then, you can do:

class Foo extend Component {
  state = { foo: 1 }
//...

and it works the same.

I hope it helps.

code of conduct - report abuse