我正在尝试使用 这个教程使 ReactJS 与 Rails 一起工作。我得到了这个错误:
Uncaught ReferenceError: React is not defined
但我可以在浏览器控制台访问 React 对象
我还按照描述的 给你添加了 Public/dist/turbo-response. min.js,并按照描述的 在这个答案中在 application.js 中添加了 //= require components
行。另外,
var React = require('react')
给出了错误信息:
Uncaught ReferenceError: require is not defined
有人能给我建议如何解决这个问题吗?
[编辑1]
参考源代码:
这是我的 comments.js.jsx
文件:
var Comment = React.createClass({
render: function () {
return (
<div className="comment">
<h2 className="commentAuthor">
{this.props.author}
</h2>
{this.props.comment}
</div>
);
}
});
var ready = function () {
React.renderComponent(
<Comment author="Richard" comment="This is a comment "/>,
document.getElementById('comments')
);
};
$(document).ready(ready);
这是我的 index.html.erb
:
<div id="comments"></div>