Reputation: 11
Warning: React.createElement: type should not be null, undefined, boolean, or number. It should be a string (for DOM elements) or a ReactClass (for composite components).
I am currently putting a react page together and have come across the error above when I try to use es2015 style code. When i use the following code I get the error
var React = require('react');
export default class StoreApp extends React.Component {
getInitialState() {
return null;
}
render() {
return (
<div>
<p>This should display on the screen</p>
</div>
);
}
}
This works fine...
var React = require('react');
var StoreApp = React.createClass({
render: function() {
return (
<div>
<p>This should display on the screen</p>
</div>
);
}
});
module.exports = StoreApp;
Im using babel with the following presets ['react','es2015'] any ideas whats going on here?
Upvotes: 1
Views: 3094
Reputation: 3392
In an es6 you can't use getInitialState()
. Use constructor()
.
e.g.
constructor(props) {
super(props);
//Set your state here using this.state = {};
//or leave blank if you don't want anything set in state
}
If you're not putting anything in state you can even leave the constructor out in an es6 class.
Upvotes: 1