reactjs - React-Rails Unexpected Token Error for any function other than render() -
i getting unexpected token error whenever add function before render().
for example:
var app = react.createclass({ constructor() { super(); this.state = { notebooks: {} }; } render: function() { return ( <div style={{"height": "100%"}}> <notebooknav notebooks={this.props.notebooks}></notebooknav> <technique></technique> </div> ); } }); this component compiles fine when delete constructor() function, constructor(), throws unexpected token error pointing @ render: function(). have ideas on how fix this?
you're confusing syntax here. createclass takes object argument, not es6 class. objects need commas separating items. also, plain objects don't have constructor class does. in react's createclass object spec want getinitialstate instead
react.createclass({ getinitialstate() { return { notebooks: {} } }, // <--- comma render() {...} }) you rewrite entire thing using es6 class (which not have commas separating methods.
class app extends react.component { constructor() { super(); this.state = { notebooks: {} }; } // <--- no comma render() { return ( <div style={{"height": "100%"}}> <notebooknav notebooks={this.props.notebooks}></notebooknav> <technique></technique> </div> ); } }
Comments
Post a Comment