gianni404
gianni404

Reputation: 11

Why doesn't my Hello World work in react?

Can you please tell me where is the bug in this code?

index.html:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
    <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
    <script src="https://unpkg.com/react@17/umd/react.development.js" crossorigin></script> 
    <script src="https://unpkg.com/react-dom@17/umd/react-dom.development.js" crossorigin></script>
    <script src="main.js" type="text/babel"></script>
  </head>
  <body>
        
    <div id="app"></div>

   
  </body>
</html>

main.js:

ReactDOM.render(<h1>Hello World</h1>, document.getElementById("#app"));

Upvotes: 0

Views: 155

Answers (2)

Daniel
Daniel

Reputation: 1472

You do NOT need the hash symbol (#) when using document.getElementById. That is only required when using document.querySelector

ReactDOM.render(<h1>Hello World</h1>, document.getElementById("app"));
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<div id="app"></div>

Upvotes: 2

Muhammad Ali
Muhammad Ali

Reputation: 2648

Actually you don't need to append # in document.getElementById so it will become: ReactDOM.render(<h1>Hello World</h1>, document.getElementById("app"));

Upvotes: 0

Related Questions