javascript - Warning: React.createElement: type should not be null, undefined, boolean, or number -
warning: react.createelement: type should not null, undefined, boolean, or number. should string (for dom elements) or reactclass (for composite components).
i putting react page , have come across error above when try use es2015 style code. when use following code error
var react = require('react'); export default class storeapp extends react.component { getinitialstate() { return null; } render() { return ( <div> <p>this should display on screen</p> </div> ); } }
this works fine...
var react = require('react'); var storeapp = react.createclass({ render: function() { return ( <div> <p>this should display on screen</p> </div> ); } }); module.exports = storeapp;
im using babel following presets ['react','es2015'] ideas whats going on here?
in es6 can't use getinitialstate()
. use constructor()
.
e.g.
constructor(props) { super(props); //set state here using this.state = {}; //or leave blank if don't want set in state }
if you're not putting in state can leave constructor out in es6 class.
Comments
Post a Comment