Using create-react-class in your React apps

In React 16, Facebook are deprecating the React.createClass() syntax for creating new components, preferring the new ES6 class method. Already from React 15.5.0, they start reminding you about this.

They favour replacing

var Greeting = React.createClass ();


class Greeting extends React.Component {}

You should absolutely upgrade to the new ES6 way but that involves some refactoring other parts of the app so if you just want the warnings to go away for now, you need to install the create-react-class npm module and then swap out the parts of your code where it says React.createClass for createReactClass. As they say, it really is a drop-in replacement.
Step 1.

yarn add create-react-class


$ npm install create-react-class —save


Step 2.

Old code

var MyComponent = React.createClass(….

New Code (remember to import the module)

import createReactClass from 'create-react-class';
var MyComponent = createReactClass({

Very simple but not clearly documented anywhere I could find.

Leave a Reply

Your email address will not be published. Required fields are marked *