Home > Software design >  how to connect react js
how to connect react js

Time:04-03

Hello guys i'm new for use react, i have problem because my react js cannot working. This is my code Index.html:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <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>
    <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
  <body>
    <div id="root"></div>
    <script src="index.js" type="text/babel"></script>
  </body>
</html>

Index.js:

ReactDOM.render(`<h1>

Hello World`</h1>

, document.getElementById("root"));

I want to connect my index.js and show hello world properly

CodePudding user response:

You don't need the quotes in the first argument. It's like writing html. But if you have multiple sibling elements put them inside one parent element. Try:

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

CodePudding user response:

Probably just the following piece of code

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

Should be corrected with

ReactDOM.render({<h1>Hello World</h1>}, document.getElementById("root"));
  • Related