0 votes
in ReactJS by
Does the statics object work with ES6 classes in React?

1 Answer

0 votes
by

No, statics only works with React.createClass():

someComponent= React.createClass({

  statics: {

    someMethod: function() {

      // ..

    }

  }

})

But you can write statics inside ES6+ classes as below,

class Component extends React.Component {

  static propTypes = {

    // ...

  }

  static someMethod() {

    // ...

  }

}

or writing them outside class as below,

class Component extends React.Component {

   ....

}

Component.propTypes = {...}

Component.someMethod = function(){....}

...