So I have been learning my first lecture on React, and playing around with my code to understand how it works, But In code-pen my code is running, but in VS code it's not.
Here's the code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="index.css">
<title>Basic-React</title>
</head>
<body>
<div id="root">not rendered</div>
<script crossorigin src="https://unpkg.com/react@17/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@17/umd/react-dom.development.js"></script>
<script>
// Your custom js code goes here
const App = () => {
return React.createElement(
"div",
{},
React.createElement("h1",{}, "Adopt-me")
)
}
ReactDOM.render(<h1>Karan</h1>, document.getElementById('root'))
// ReactDOM.render(React.createElement(App), document.getElementById("root"))
</script>
</body>
</html>
My ReacDOM.render call is giving an error on the browser as :
index.html:25 Uncaught SyntaxError: Unexpected token '<'
But if run this code in codepen or say proper react-package installation with node, It's running
Why?
question from:
https://stackoverflow.com/questions/65840918/reactdom-not-rendering-the-simple-h1-element 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…