handsonlab
handsonlab
By the end of this lab, create HTML Pages with React Components and React applications.
Prerequisites
1. cd /home/project
Copied!
1. ls /home/project
Copied!
Copied!
1. cd lkpho-Cloud-applications-with-Node.js-and-React/CD220Labs/
Copied!
6. List the contents of react_pages. This should contain HTML page(s) which you can download and view in your
local system.
1. 1
1. ls react_pages
Copied!
7. List the contents of todoapp. This should contain a directory structure with a pre-installed react app.
1. 1
1. ls todoapp
Copied!
8. List the contents of react-apps. This should contain a directory structure with a pre-installed react app that
you can change to apply what you have learned.
1. 1
1. ls react-apps
Copied!
These are the two directories you will be using for this lab.
3. Now open the downloaded file in your local browser. The page will appear as below.
Exercise 2: First React Application
The todoapp is a react app that has been created for you using npx create-react-app todoapp command. In the files
explorer view todoapp directory. It would appear like this.
2. In the terminal window run the following commands one after the other.
1. 1
2. 2
3. 3
1. cd todoapp
2. npm install
3. npm start
Copied!
The first command changes to the todoapp directory. Second command installs the files required for the React app in
your lab environment and the third one starts the server.
You will see this output indicating that the server is running.
3. Click on the button below to open the React application on new browswer tab or click Skills Network button
on the left, choose the Other option and then click Launch Application and connect to port 3000.
REACT Application
The todoapp UI will appear on the browser as seen in the image below.
4. To stop the server, go to the main command window and press Ctrl+c to stop the server.
2. In the terminal window run the following commands one after the other.
1. 1
2. 2
3. 3
1. cd /home/project/lkpho-Cloud-applications-with-Node.js-and-React/CD220Labs/react-apps
2. npm install
3. npm start
Copied!
The first command changes to the react-apps directory. Second command installs the files required for the React
app in your lab environment and the third one starts the server.
You will see this output indicating that the server is running.
3. To see what UI this React app renders, click on the Skills Network button on the left, it will open the “Skills
Network Toolbox”. Then click the Other then Launch Application. From there enter the port number the
server is running on, which is 3000 and then launch.
The react-apps UI will appear on the browser. All the styling has been removed and you should see Hello World
written on the page.
4. View the content on App.js under react-apps->src in the file explorer. It will appear as below.
5. Now let’s start adding a component to the page. When the server is running, any change made to the files is
automatically picked up by the server.
1. function App() {
2. return (
3. <div >
4. Hello World!
5. </div>
6. );
7. }
8.
9. export default App;
Copied!
It is a function component. Let’s make changes to the code to accept the color as props.