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
Post a Comment