React, Uncaught ReferenceError: ReactDOM is not defined

前端 未结 6 862
渐次进展
渐次进展 2021-02-07 02:39

I am doing this Router tutorial.

My App.jsx file:

import React from \'react\';
import ReactDOM from \'react-dom\';
import { Router, Route, Link, browserH         


        
6条回答
  •  花落未央
    2021-02-07 03:10

    You need to import ReactDOM in Main.js instead of App.jsx, as Main is where you are using ReactDOM to render.

    Also need to import React in all files that use JSX.

    Finally, also put react-router imports into Main, too.

    The way imports work is, you import things you need, in places they're needed. It's not enough to import them once in one file and use in others.

    Change Main.js to look like

    import ReactDOM from 'react-dom'
    import React from 'react'
    import { Router, Route, browserHistory, IndexRoute  } from 'react-router'
    
    ReactDOM.render((
    
      
         
         
         
         
      
    
    
    ), document.getElementById('app'))
    

提交回复
热议问题