React-rails: Syntax error when set defaultProps for components

Created on 4 Jul 2016  路  4Comments  路  Source: reactjs/react-rails

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-rails with 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?

screen shot 2016-07-04 at 17 11 56

Thank you very much.

Most helpful comment

Not clear to me, how do I add stage2 to react-rails?

All 4 comments

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?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

okolomoets picture okolomoets  路  5Comments

ghost picture ghost  路  4Comments

scottbarrow picture scottbarrow  路  5Comments

wenwei63029869 picture wenwei63029869  路  3Comments

davidlormor picture davidlormor  路  3Comments