Reputation: 1834
So i have Rails applications, i installed react-rails gem, set it up and try to run test application.
Freshly installed, when i tryed to run hello world program, this error hapened:
Uncaught ReferenceError: ReactDOM is not defined
This is my react:
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);
Its saved inside /app/assets/javascripts/components/test.js.jsx file.
Rails 4.2.4 With Ruby 2.2.3
Upvotes: 53
Views: 99348
Reputation: 197
Make sure it's ReactDOM (case sensitive)
class App extends React.Component {
render() {
return (
<div>
<div className="commentbox">Hello React ! </div>
</div>
);
}
}
ReactDOM.render(<App />, document.getElementById('root'));
Upvotes: 5
Reputation: 3108
To make it work properly, you have to do 3 things.
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
install babel-cli
. It is needed for the compilation of JSX into vanila js
change the typo in your code,
it is ReactDOM
, not RaactDOM
Upvotes: 0
Reputation: 3518
It may be the spelling issue - it is ReactDOM
, not ReactDom
.
This has changed over time with the new release of React
Upvotes: 89
Reputation: 77482
ReactDOM
available since version 0.14.0, so you need to use React.render
(because you have a React version 0.13.3) instead,
setInterval(function() {
React.render(
<HelloWorld date={new Date()} />,
document.getElementById('example')
);
}, 500);
or upgrade your React
version and include ReactDOM
Upvotes: 29
Reputation: 7470
Make sure that you've included react-dom.js
. You can add it from CDN or use js toolchain of your choice.
Installing React - using a CDN
<script src="https://unpkg.com/react@15/dist/react.js"></script>
<script src="https://unpkg.com/react-dom@15/dist/react-dom.js"></script>
Upvotes: 9