search

Home  >  Q&A  >  body text

React.js code is not displayed correctly in the web page

My code is very simple. I checked all the resources, rewrote the code into different files, updated my computer, checked the css files and everything is fine and I can't see the problem.

react.html:

<html>
    <head>
        <link rel="stylesheet" href="react.css">
        <script crossorigin src="https://unpkg.com/react@18/umd/react.development.js"></script>
        <script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"><script>
    </head>
    <body>
        
       <div id="root"></div>
        <script src="react.js" type="text/babel"></script>
    </body>
</html>

react.js:

ReactDOM.render(<h1>Hello, World!</h1>, document.querySelector("#root"))
```  tried  document.getElementById("root") as well

P粉510127741P粉510127741348 days ago542

reply all(1)I'll reply

  • P粉373596828

    P粉3735968282024-01-11 09:12:30

    To use @babel/standalone you also need to load it, otherwise type="text/babel" won't work.

    <!-- 加载 Babel -->
    <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>

    reply
    0
  • Cancelreply