51

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

JonasVautherin
  • 7,297
  • 6
  • 49
  • 95
IvRRimUm
  • 1,724
  • 3
  • 21
  • 40

6 Answers6

86

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

This has changed over time with the new release of React

Adam
  • 3,415
  • 4
  • 30
  • 49
  • Something strange is happening here. I'm not sure that this should be correct based on the tutorial available (https://facebook.github.io/react/docs/tutorial.html) but my app actually started working when I changed ReactDom to ReactDOM when using 15.0.1 and ReactDom 15.0.1. – Grisk Apr 20 '16 at 18:32
  • 5
    Unbelievable. Just spent an hour tearing my hair out making wrong assumptions as to why SystemJS (that's what I was using) was telling me ReactDom was undefined. Finally saw this answer, replaced the spelling to ReactDOM, and it works...Oh boy. – Gilad Barner Jun 08 '16 at 15:32
  • Perfect click boss! – Chandresh M May 21 '19 at 12:48
  • Very common error. I've done this many times with ReactDOM. Watch out for it. – Harlin Aug 09 '19 at 01:00
29

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

Oleksandr T.
  • 76,493
  • 17
  • 173
  • 144
  • 1
    That did the trick, i got another error, but i think i will just remove the gem and install newest react version manualy. Thanks for the response!!! – IvRRimUm Oct 14 '15 at 12:56
18

You have to import it

import ReactDOM from 'react-dom';
Kay
  • 402
  • 4
  • 6
9

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>
Seppo Erviälä
  • 7,160
  • 7
  • 35
  • 40
3
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'));
Adarsh Babu PR
  • 179
  • 1
  • 5
0

To make it work properly, you have to do 3 things.

  1. Import the CDNs, necessary for the developement(Say react and react-dom for web development)
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
  1. install babel-cli . It is needed for the compilation of JSX into vanila js

  2. change the typo in your code,

it is ReactDOM , not RaactDOM

Anand Raja
  • 2,676
  • 1
  • 30
  • 35