React, ES6 – getInitialState was defined on a plain JavaScript class

  • getInitialState is not used in ES6 classes. Instead assign this.state in the constructor.
  • propTypes should be a static class variable or assigned to the class, it should not be assigned to component instances.
  • Member methods are not “auto-bound” in ES6 classes. For methods used as callbacks, either use class property initializers or assign bound instances in the constructor.
export default class RadioOther extends React.Component {

  static propTypes = {
    name: React.PropTypes.string.isRequired,
  };

  constructor(props) {
    super(props);
    this.state = {
      otherChecked: false,
    };
  }

  // Class property initializer. `this` will be the instance when
  // the function is called.
  onRadChange = () => {
    ...
  };

  ...

}

See more in the React’s documentation about ES6 Classes: Converting a Function to a Class

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)