所以我有Rails应用程序,我安装了react-rails gem,对其进行设置并尝试运行测试应用程序。
刚安装时,当我尝试运行hello world程序时,发生此错误:
未捕获的ReferenceError:未定义ReactDOM
这是我的反应:
var HelloWorld = React.createClass({ render: function() { return ( <p> Hello, <input type="text" placeholder="Your name here" />! It is {this.props.date.toTimeString()} </p> ); } }); setInterval(function() { ReactDOM.render( <HelloWorld date={new Date()} />, document.getElementById('example') ); }, 500);
它保存在/app/assets/javascripts/components/test.js.jsx文件中。
Rails 4.2.4和Ruby 2.2.3
ReactDOM自 0.14.0 版 开始提供 ,因此您需要使用React.render(因为您有一个React版本 0.13.3 ),
ReactDOM
React.render
setInterval(function() { React.render( <HelloWorld date={new Date()} />, document.getElementById('example') ); }, 500);
或升级您的React版本并包括ReactDOM
React
React 0.14的变化