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
Post a Comment