Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught ReferenceError: ReactDOM is not defined

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

like image 894
IvRRimUm Avatar asked Oct 14 '15 12:10

IvRRimUm


People also ask

How do you define ReactDOM?

ReactDOM is a package that provides DOM specific methods that can be used at the top level of a web app to enable an efficient way of managing DOM elements of the web page. ReactDOM provides the developers with an API containing the following methods and a few more. render() findDOMNode()

How do I import ReactDOM into react?

import ReactDOM from 'react-dom'; or if you're using ES5 you can just do: var ReactDOM = require('react-dom'); and then you can use ReactDOM.

Is not defined no unde?

js error "X is not defined react/jsx-no-undef" occurs when we forget to import a function, class or a variable in our code before using it. To solve the error, make sure to import the value before using it in your code, e.g. import {myFunc} from 'my-package' . Copied!


2 Answers

It may be the spelling issue - it is ReactDOM, not ReactDom.

This has changed over time with the new release of React

like image 123
Adam Avatar answered Sep 21 '22 18:09

Adam


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

Changes in React 0.14

like image 33
Oleksandr T. Avatar answered Sep 18 '22 18:09

Oleksandr T.