Uncaught ReferenceError: React is not defined

前端 未结 12 1797
予麋鹿
予麋鹿 2020-11-30 02:17

I am trying to make ReactJS work with rails using this tutorial. I am getting this error:


Uncaught ReferenceError: React is not defined

相关标签:
12条回答
  • 2020-11-30 02:32

    The displayed error

    after that import react

    Finally import react-dom

    if error is react is not define,please add ==>import React from 'react';

    if error is reactDOM is not define,please add ==>import ReactDOM from 'react-dom';

    0 讨论(0)
  • 2020-11-30 02:35

    I got this error because I was using

    import ReactDOM from 'react-dom'
    

    without importing react, once I changed it to below:

    import React from 'react';
    import ReactDOM from 'react-dom';
    

    The error was solved :)

    0 讨论(0)
  • 2020-11-30 02:35

    I was facing the same issue. I resolved it by importing React and ReactDOM like as follows:

    import React from 'react';
    import ReactDOM from 'react-dom';
    
    0 讨论(0)
  • 2020-11-30 02:38

    Try to add:

    import React from 'react'
    import { render } from 'react-dom'
    window.React = React
    

    before the render() function.

    This sometimes prevents error to pop-up returning:

    React is not defined

    Adding React to the window will solve these problems.

    0 讨论(0)
  • 2020-11-30 02:38

    I got this error because in my code I misspelled a component definition with lowercase react.createClass instead of uppercase React.createClass.

    0 讨论(0)
  • 2020-11-30 02:42
    import React, { Component, PropTypes } from 'react';
    

    This may also work!

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