最佳答案
I'm tring the ES6 syntax in React, and write the components like:
export default class Loginform extends React.Component {
getInitialState() {
return {
name: '',
password: ''
};
};
}
but the browser throws me a waring about:
Warning: getInitialState was defined on Loginform, a plain JavaScript class. This is only supported for classes created using React.createClass. Did you mean to define a state property instead?
I can handle it with the traditional syntax var Loginform = React.createClass
but what's correct ES6 syntax?
Another little thing, I think in traditional syntax React.createClass
is an object, so the functions in it is separated by comma, but with the extends
class it require semicolon, I don't understand it well.