You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class User extends React.Component {
state = {
username: 'Tyler'
}
}
// rather than
class User extends React.Component {
constructor(props) {
super(props);
this.state = {
username: 'Tyler'
}
}
}
This is slightly different from Facebook's Setting the Initial State docs.
Having state outside the constructor() means it is a class field, which is a proposal for a new change to the language. It currently isn't supported by JavaScript, but thanks to Babel's fantastic powers of transpiling, we can use it!