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(){....}

Related questions

0 votes
asked Mar 2, 2020 in ReactJS by RShastri
0 votes
asked Nov 10, 2023 in ReactJS by GeorgeBell
...