Skip to content

state in constructor or not  #1

@yuminatwca

Description

@yuminatwca

Hi, Ninja,

I have watched the 2 series of your React toturials, and I have noticed that you like to use state directly in the class, instead of to put it in the constructor like the React documentation does.

class Foo extends Component{
   state: { 
        name: "Shaun"
   }
}


class Bar extends Component {
    constructor(props){
      super(props);
      this.state= { 
        name: "Shaun"
      }
    }

}

So, would you please explain it a little bit about why you prefer to use state like the above class Foo ? Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions