简体   繁体   中英

My hello world React not appear

I am new to React. I read the official tutorial of React and I try to create a basic hello world react app but I dont succeed. I looked in the web and also here for an answer and I didnt find one. Can you please tell me what I am missing and what I need to do? The following is my html and javascript files:

 import React from 'react'; import ReactDOM from 'react-dom'; ReactDOM.render( <h1>Hello, World</h1>, document.getElementById('root') ); 
 <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Page Title</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css"> <script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin></script> <script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin></script> <script type="text/jsx" src="inputPhoneNumber.js"></script> </head> <body> <div class="jumbotron jumbotron-fluid"> <div id="root" class="container"> </div> </div> </body> </html> 

All you should need is the react and react-dom scripts like you already have, a root element like the div with id root you have, and a file which uses ReactDOM to render the topmost component into the root element.

Example

 ReactDOM.render( React.createElement('h1', {}, 'Hello, World'), document.getElementById('root') ); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script> <div id="root"></div> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM