Rails-React不能与ES6一起使用

Dil*_*tez 5 javascript ruby ruby-on-rails reactjs react-rails

我正在使用react-rails gem,我正在尝试在ES6中编写一些看起来像这样的组件.

我的link_list.js.jsx文件

import Component from 'react';
import Links from 'link';

class LinkList extends React.component{
  constructor(props){
    super(props);
    this.sate = {};
  }

  getInitialState(){
    return { links: this.props.initialLinks}
  }


  render(){
    var links = this.state.links.map(function(link){
      return <Links key={link.id} link={link} />
    })

    return (
      <div className="links">
        {links}
      </div>
    )
  } 
}
Run Code Online (Sandbox Code Playgroud)

我一直得到这个Uncaught ReferenceError: require is not defined 和一个错误说Warning: React.createElement: type should not be null, undefined, boolean, or number. It should be a string (for DOM elements) or a ReactClass (for composite components).

和错误 Uncaught Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.

这是我的代码的问题还是宝石没有编译ES6的问题?

Edm*_*Lee 2

生成命令中有一个选项

rails generate react:component Label label:string --es6

https://github.com/reactjs/react-rails#options

否则,您可以使用webpack设置前端并使用babel.