React.js code is not displayed correctly in the web page
P粉510127741
P粉510127741 2024-01-10 18:10:59
0
1
532

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粉510127741
P粉510127741

reply all(1)
P粉373596828

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>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template