Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning: getInitialState was defined on a plain JavaScript class, even when using React.creatClass #4214

Closed
dmatteo opened this issue Jun 24, 2015 · 3 comments

Comments

@dmatteo
Copy link
Contributor

dmatteo commented Jun 24, 2015

I'm trying to migrate our code base from 0.12.x to 0.13.x

One of the most recurring warnings though seems a bit weird:
'Warning: getInitialState was defined on Component, a plain JavaScript class. This is only supported for classes created using React.createClass. Did you mean to define a state property instead?'

This is the actual component, and it's a RequireJS module, as you can see.

define(function(require) {
  'use strict';

  var React = require('react');

  var Component = React.createClass({
    displayName: 'Component',

    getInitialState() {
      return {
        whatever: 'React!'
      };
    },

    render() {
      return <div>Hello {this.state.whatever}</div>
    }
  });

  return Component;

})

Am I doing something wrong inadvertently?

@dmatteo dmatteo changed the title getInitialState was defined on a plain JavaScript class, even when using React.creatClass Warning: getInitialState was defined on a plain JavaScript class, even when using React.creatClass Jun 24, 2015
@sophiebits
Copy link
Collaborator

That code looks fine. Can you post a simple jsbin that reproduces the problem?

@dmatteo
Copy link
Contributor Author

dmatteo commented Jun 25, 2015

@spicyj shame on me...
It's actually something that we did in our early days in React messing with type.prototype.getInitialState 👎

I've killed that and it doesn't throw that warning anymore.

Thanks,
See ya!

@dmatteo dmatteo closed this as completed Jun 25, 2015
@NickStefan
Copy link

when i directly require react and react dom min, i get this same error, even though we are only using React.createClass:

webpack directly requiring the min versions for our server build

externals: [
            {
                react: false,
                'react-dom': false
            },
            /^[a-z\-0-9]+$/
        ],
        resolve: {
            alias: {
                react: pathToReactMin,
                'react-dom': pathToReactDomMin
            }
        },

the reason i was wanting to directly require the min versions was #812

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants