reactjs - When should I use getInitialState in a React component -


i have react component toggles classname when component clicked

var foo = react.createclass({   getinitialstate: function() {     return {classname: ''}   },    render: function(){     var classname = 'bar ' + this.state.classname     return react.createelement('div', {classname: classname, onclick: this.onclick})   },    onclick: function() {     this.setstate({classname: 'baz'})   } }); 

it works fine, when rendering app server side, following error

warning: getinitialstate defined on component, plain javascript class. supported classes created using react.createclass. did mean define state property instead? 

my build step setup so

var foo = require('./foo'); var factory = react.createfactory(foo); module.exports = react.rendertostring(factory({})); 

why doing wrong, , how should done?

i not sure if helps, while using fluxible, syntax used jsx part of require component

var app = new fluxible({   component: react.createfactory(require('./components/startup.react.jsx')) }); 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -