Uncaught ReferenceError: ReactDOM is not defined

后端 未结 5 1990
半阙折子戏
半阙折子戏 2021-02-01 01:26

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 er

相关标签:
5条回答
  • 2021-02-01 01:49

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

    This has changed over time with the new release of React

    0 讨论(0)
  • 2021-02-01 02:00

    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

    0 讨论(0)
  • 2021-02-01 02:01

    You have to import it

    import ReactDOM from 'react-dom';
    
    0 讨论(0)
  • 2021-02-01 02:01

    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>
    
    0 讨论(0)
  • 2021-02-01 02:07

    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

    0 讨论(0)
提交回复
热议问题