Skip to content
Related Articles

Related Articles

How to create Loading Screen in ReactJS ?

View Discussion
Improve Article
Save Article
  • Difficulty Level : Easy
  • Last Updated : 31 Oct, 2021

In this article, we are going to learn how we can create Loading Screen in ReactJs. A loading screen is a picture shown by a computer program, often a video game, while the program is loading or initializing.

React is a free and open-source front-end JavaScript library for building user interfaces or UI components. It is maintained by Facebook and a community of individual developers and companies.

Approach: To create our loading screen we are going to use the react-loading package because it is powerful, lightweight, and fully customizable. After that, we will add different types of loading screens on our homepage using the installed package.


Create ReactJS Application: You can create a new ReactJs project using the below command:

npx create-react-app gfg

Install the required package: Now we will install the react-loading package using the below command:

npm i react-loading

Project Structure: It will look like this.

Adding Loading Screen: In this example, we are going to add the react-loading on the homepage of our app using the package that we installed. For this, add the below content in the App.js file.


import React from "react";
import ReactLoading from "react-loading";
export default function Loading() {
  return (
      <h2>Loading in ReactJs - GeeksforGeeks</h2>
      <ReactLoading type="balls" color="#0000FF" 
        height={100} width={50} />
      <ReactLoading type="bars" color="#0000FF"
        height={100} width={50} />
      <ReactLoading type="bubbles" color="#0000FF"
        height={100} width={50} />
      <ReactLoading type="cubes" color="#0000FF"
        height={100} width={50} />
      <ReactLoading type="cylon" color="#0000FF" 
        height={100} width={50} />
      <ReactLoading type="spin" color="#0000FF"
        height={100} width={50} />
      <ReactLoading type="spokes" color="#0000FF"
        height={100} width={50} />

Explanation: In the above example first, we are importing the ReactLoading component from the react-loading package. After that, we are using our ReactLoading component to add different types of loading screens. We can set the type, color, height, and width of the loading screen.

Steps to run the application: Run the below command in the terminal to run the app.

npm start


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!