admin管理员组文章数量:1389768
I just started to play around with the react gem but I seem to running into issues. With the code below, whenever I get routed to my react example page, I notice in the browser developer console, it will say "React is not defined." It's referring to this line:
var react_example = React.createClass({
which is in the react_example.js.jsx file (see below).
Gemfile
#... as well as other gems...
gem 'nokogiri'
gem 'react-rails' #<------ React
gem 'less-rails'
gem 'therubyracer'
gem 'twitter-bootstrap-rails', :git => 'git://github/seyhunak/twitter-bootstrap-rails.git'
development.rb
config.react.variant = :development
config.react.addons = true
application.html.erb
<!DOCTYPE html>
<html>
<head>
<title>React example</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= javascript_include_tag "react" %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
</body>
</html>
react_example.js.jsx
/** @jsx React.DOM */
var react_example = React.createClass({
render: function () {
return (
<div>
<h5>React</h5>
</div>
);
}
});
I just started to play around with the react gem but I seem to running into issues. With the code below, whenever I get routed to my react example page, I notice in the browser developer console, it will say "React is not defined." It's referring to this line:
var react_example = React.createClass({
which is in the react_example.js.jsx file (see below).
Gemfile
#... as well as other gems...
gem 'nokogiri'
gem 'react-rails' #<------ React
gem 'less-rails'
gem 'therubyracer'
gem 'twitter-bootstrap-rails', :git => 'git://github./seyhunak/twitter-bootstrap-rails.git'
development.rb
config.react.variant = :development
config.react.addons = true
application.html.erb
<!DOCTYPE html>
<html>
<head>
<title>React example</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= javascript_include_tag "react" %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
</body>
</html>
react_example.js.jsx
/** @jsx React.DOM */
var react_example = React.createClass({
render: function () {
return (
<div>
<h5>React</h5>
</div>
);
}
});
Share
Improve this question
asked Jul 26, 2014 at 18:58
theStigtheStig
6101 gold badge13 silver badges33 bronze badges
2 Answers
Reset to default 2Try switching your JS includes:
<%= javascript_include_tag "react" %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
Since you use React in your application JS, it needs to be defined first.
That's actually not the best way to do it, unless you really wanna load react apart from your application.
The documentation states clearly you should do this inside your application.js manifest file:
//= require react
//= require react_ujs
//= require ponents
The line that mention "ponents" depends on the folder you actually puts your react ponent files.
本文标签: javascriptReact is not definedStack Overflow
版权声明:本文标题:javascript - React is not defined - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744692564a2620081.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论