Syntax error when set defaultProps for components
Help us help you! Please choose one:
- [x] My app crashes with
react-rails, so I've included the stack trace and the exact steps which make it crash. - [ ] My app doesn't crash, but I'm getting unexpected behavior. So, I've described the unexpected behavior and suggested a new behavior.
- [ ] I'm trying to use
react-railswith another library, but I'm having trouble. I've described my JavaScript management setup (eg, Sprockets, Webpack...), how I'm trying to use this other library, and why it's not working. - [ ] I have another issue to discuss.
(Describe your issue here)
I wrote a simple component and I want to set its defaultProps. But this weird error occurred. How am I supposed to deal with this?
Thank you very much.
I suspect that this requires a different Babel setting than the default in react-rails. You could try customizing BabelTransformer https://github.com/reactjs/react-rails/blob/master/lib/react/jsx/babel_transformer.rb
Sorry, I use createClass so I don't have much experience here! 😬
You need Babel stage: 0 for static properties to work on ES6 Classes. We use stage2 and write ours like this.
class Foo extends Component {}
Foo.propTypes = {};
Foo.defaultProps = {};
export default Foo;
Thanks @coryasato ! Stage 2 is safer than stage 0 right? I will use stage 2.
Not clear to me, how do I add stage2 to react-rails?