Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
353 views
in Technique[技术] by (71.8m points)

javascript - How can I output hello world in this simple React code?

enter image description hereI used create-react-app from npm to start a new react project. I wanted to use this to do the learn react course on Scrimba. I installed everything without any problems. I deleted all the src files as ill be copying new ones from Scrimba but I kept absolutely everything else.

I currently have the following in my index.js file

import React from 'react';
import ReactDOM from 'react-dom';

ReactDOM.render(<div><h1>Hello world!</h1></div>, document.getElementById('root'));

and a html file

<html>
    <head>
        <link rel="stylesheet" href="style.css">
    </head>
    <body>
      <h1>placeholder</h1>
        <div id="root"></div>
        <script src="index.pack.js"></script>
    </body>
</html>

When I load the html file, I can see 'placeholder', but not 'Hello World!' I've also included an image of the file layout. I also included a screenshot in case my layout or something is wrong. Any help appreciated! (I've already posted almost the same problem but was advised to post a better/updated version)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There already is an index.html file in your public folder. No need to create a new one.

You should start looking at your index.js file. It points to app.js, which is an example react component you can start editing and playing around with.

Make sure to open a terminal and start your react app with npm install followed by npm start.

I would suggest reading some documentation. The official react website is great. https://reactjs.org/tutorial/tutorial.html


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...