reactjs - Class extends React.Component can't use getInitialState in React -


i'm tring es6 syntax in react, , write components like:

export default class loginform extends react.component {     getinitialstate() {         return {           name: '',           password: ''         };     }; } 

but browser throws me waring about:

warning: getinitialstate defined on loginform, plain javascript class. supported classes created using react.createclass. did mean define state property instead?

i can handle traditional syntax var loginform = react.createclass what's correct es6 syntax?

another little thing, think in traditional syntax react.createclass object, functions in separated comma, extends class require semicolon, don't understand well.

you don't need semicolons or commas between es6 class method declarations.

for es6 classes, getinitialstate has been deprecated in favor of declaring initial state object in constructor:

export default class loginform extends react.component {   constructor(props, context) {     super(props, context);      this.state = {       name: '',       password: ''     };   }; } 

Comments

Popular posts from this blog

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -