I started learning about React and I have problem with importing the library.
index.html:
JavaScript
x
8
1
<body>
2
<div id="root"></div>
3
4
<script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin></script>
5
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin></script>
6
<script src="script.js"></script>
7
</body>
8
script.js file:
JavaScript
1
5
1
import React from "react";
2
import ReactDOM from "react-dom";
3
4
ReactDOM.render(<h1> Hello World </h1>, document.getElementById("Root"))
5
Error I get when im opening the index file:
Cannot GET /ReactDOM%20%5E&%20JSX/index.html
I imported those 2 scripts from React site.
Advertisement
Answer
I noticed that the id on <div id="root"></div>
is lowercase but in your JS script you’re selecting document.getElementById("Root")
an uppercase id. document.getElementById
is case sensitive, so your code will probably not render correctly.