How to fix React createClass is not a function problem

Are you trying to use React.createClass?

And you’re seeing this error message:


TypeError: React.createClass is not a function

That’s because this function does not exist in the newer version of React since the majority applications are using ES6 syntax now.

But there are rare occasions where you will need to use that old syntax.

It could because you’re getting data from an API, that returns properties to create a dynamic component or such.

Solution: Install create-react-class

You can solve the problem by installing Facebook NPM module create-react-class.


npm install create-react-class

Let’s see how to use it now.


import * as React from "react";
import { render } from "react-dom";
import createClass from 'create-react-class';

const App = createClass({
  render: () => <h1>This is coming from createClass() function</h1>,
});

Happy coding!

I like to tweet about code and post helpful code snippets. Follow me there if you would like some too!