How to create a simple React js single page application?

In this particular post, we will learn to create a single React js single page application. React JS uses JSX — it helps us in keeping code simpler and elegant when writing large pieces of code. The popularity of React JS is well known for providing component-driven rich user interfaces. Nowadays most of the tools and respective applications are coming with reusable React components.

This exercise page will have a button to retrieve the random user from an API. It helps to understand the basics of React JS and the usage of API communication within it.

  1. Codesandbox — To develop the React JS project
  2. Random User API — It is an open-source free API that gives random user data

Navigate to https://codesandbox.io/ — Codesandbox URL. Click on the React JS.

It will open up the code editor window as below

Rename the App.js to “RandomUserExample.js” and copy the following code.

The following code is self-explanatory from the JSX perspective.

Update the references in the index.js as below — To replace the App to RandomUserExample component.

In the Styles.css file — Update with the following content

Note: For styling the application, If you are new then I recommend using Figma.

Step 4: Testing the application

On the right-hand side, you can see a random user button to retrieve the random user from the API.

Hurray, congratulations :) Now you successfully completed a React JS Single page application to use an API to get the information.

--

--

Digital Transformation Leader | Pega Lead Solution Architect | Pega Certified Data Scientist | Pega Customer Service | Pega Sales Automation | AWS Cloud

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sandeep Pamidamarri

Digital Transformation Leader | Pega Lead Solution Architect | Pega Certified Data Scientist | Pega Customer Service | Pega Sales Automation | AWS Cloud