Saturday, January 11, 2025
Google search engine
HomeLanguagesHow to create Loading Screen in ReactJS ?

How to create Loading Screen in ReactJS ?

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.

Javascript




import React from "react";
import ReactLoading from "react-loading";
 
export default function Loading() {
    return (
        <div>
            <h2>Loading in ReactJs - neveropen</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} />
            <ReactLoading
                type="spinningBubbles"
                color="#0000FF"
                height={100}
                width={50}
            />
        </div>
    );
}


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

Output:

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments