Refactor constructor in React

This constructor can be refactored


constructor(props) {
    //call the react component constructor function.
    super(props);
    //assign state
    this.state = { lat: null, errorMessage: "" };
  }

into this:


  state = { lat: null, errorMessage: "" };

In the background, babel will take the refactored code and generate exactly the same code as above, its just a shorthand that makes the code more clear and less boilerplate.

Add your comment