Class definition in React

Kayut on January 18, 2019

Does a Class component in React need to have a constructor like the following example: class App extends React.Component { constructor() {... [Read Full]
markdown guide
 

@kayut If you don't have child class means, you can use as second option like without constructor.

 
 

👆 answers the question 👍

@kayut
And note that the state is initialized as a property outside of constructor, this. should be dropped.

class App extends React.Component {
  // not this.state but just state
  state = {
    count: 0
  };
  render() { ...  }
}
code of conduct - report abuse