How to use loading animation by using the react-loader-spinner through npm ?
Last Updated :
03 Nov, 2023
In React, loading animation by using the react-loader-spinner enhances the user experience and provides visual feedback during these loading periods. For the asynchronous operations and data fetching it works as a visual representation of the process until the data is loaded. React developers can easily add loading animations to their applications by utilizing the react-loader-spinner available through npm.
The react-loader-spinner is an npm package that provides a simple and attractive SVG spinner component that can be used in any of your projects. The spinner in react-loader-spinner is used to indicate the loading state. We can also modify the appearance, size, and placement of the spinners with the propeTypes available in the react-loader-spinner.
Syntax:
<TailSpin // Type of spinner
height="80"
width="80"
color="#4fa94d"
ariaLabel="tail-spin-loading"
radius="1"
wrapperStyle={{}}
wrapperClass=""
visible={true}
/>
Types of spinner: All types of spinner can be used similarly you just need to change the type of the loader.
- Audio
- Ball-Triangle
- Bars
- Circles
- Grid
- Hearts
- Oval
- Puff
- Rings
- TailSpin
- ThreeDots
PropTypes: All types of spinners accept these props.
- visible: It is a boolean value that defines whether the spinner should be visible or not, the default value is false.
- type: This prop defines the spinner type.
- height: This prop defines the height of the SVG spinner and the default value is 80.
- width: This prop defines the width of the SVG spinner and the default value is 80.
- color: This prop defines the color of the spinner.
- secondaryColor: This prop is available on the plane and mutatingDots loaders.
- timeout: This defines the effective time of the spinner.
- radius: This prop set the radius of the spinner.
Steps to create React Application
Step 1: Create the React app using the command.
npx create-react-app foldername
Step 2: Now move into your project folder i.e. foldername by using this command.
cd foldername
Step 3: Now install the package into your project folder.
npm install react-loader-spinner
Project Structure:

The updated dependencies after installing packages
"dependencies": {
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-loader-spinner": "^5.4.5",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
}
Example: This examle uses the loader from react-loader-spinner to show the loading animation while loading the components.
JavaScript
// Filename - App.js
import { useState } from "react";
import Loader from "./loader";
function App() {
const [isLoading, setIsLoading] = useState(true);
setTimeout(() => {
setIsLoading(false);
}, 2000);
return (
<div
style={{
textAlign: "center",
margin: "auto",
}}
>
<h1 style={{ color: "green" }}>
GeeksforGeeks
</h1>
{isLoading ? (
<div
style={{
width: "100px",
margin: "auto",
}}
>
<Loader />
</div>
) : (
<div>
<h3>
React Example to Implemet Loader
using react-loader-spinner
</h3>
</div>
)}
</div>
);
}
export default App;
JavaScript
// Filename - loader.js
import { TailSpin } from "react-loader-spinner";
const LoaderComp = () => {
return (
<TailSpin
height="80"
width="80"
color="#4fa94d"
ariaLabel="tail-spin-loading"
radius="1"
wrapperStyle={{}}
wrapperClass=""
visible={true}
/>
);
};
export default LoaderComp;
Step to Run the Application: Use this command in the terminal inside the project directory.
npm start
Output: This output will be visible on the http://localhost:3000/ on the browser window.
Similar Reads
How to Rotate Shape Loader Animation using CSS ? A rotating shape loader animation in CSS refers to an animated element, such as a circle or square, that spins continuously to indicate loading or processing. This is achieved using the @keyframes rule and CSS properties like transform: rotate() to create smooth, spinning animations. rotate shape lo
2 min read
How to Display Spinner on the Screen till the data from the API loads using Angular 8 ? The task is to display a spinner on the page until the response from the API comes. Here we will be making a simple CSS spinner which will load till the data from API comes. You can also take bootstrap spinners or can make spinner on your own. Prerequisite: You will need some knowledge for making Ht
3 min read
React animated loading/splash screen using 'react-spinners' Displaying a loading or splash screen during response time from the server is an excellent way to interact with the user. But making a loading/splash screen becomes difficult when we want to practically use an animated loader, where we need to make extra efforts to write down its styling file. To ov
2 min read
How to trigger animations in a ReactJS app based on the scroll position ? To trigger animations in a ReactJS app based on the scroll position we can define multiple component animations for the scroll values provided by windows.scrollY. When we scroll to that defined position, some animations get triggered. This provides a very nice user experience.Prerequisite:Â React JSN
4 min read
How to Create Animation Loading Bar using CSS ? Loading Bar with animation can be created using HTML and CSS. We will create a Loader that is the part of an operating system that is responsible for loading programs and libraries. The progress bar is a graphical control element used to visualize the progression of an extended computer operation, s
3 min read
Design an Animated Toggle Switch Button using framer-motion & React Animated Toggle Switch Button using framer-motion & React is a button that shows some animation/transitions and switches the states when clicked.Prerequisites:Node.js and NPM React JSReact JS HooksApproach:To design an animated toggle switch button using framer motion in react we will be using t
3 min read
How to create Gooey Balls animation using HTML & CSS ? The Gooey Balls loader is a basic CSS animation, where we will make a loader animation with two balls running in an animation effect that looks like the balls are rotating in motion. In this article, we will see how to create the rotating pass-through balls animation loader using HTML & CSS. App
2 min read
How to show Page Loading div until the page has finished loading? There are a lot of ways in which we can show a loading div but we have figured out the most optimal solution for you and that too in pure vanilla JavaScript. We will use the document.readyState property. When the value of this property changes, a readystatechange event fires on the document object.
2 min read
How to Design Fade balls loader Animation using CSS ? Minimal Fading balls loader is a basic CSS animation, where the loader animation will be utilized to engage the user until when a specific page or content is fully get loaded in a particular platform. In this article, we will see how to create a loader animation with three balls animation effect whi
2 min read
How to Create Multi Level Sidebar Animation in React ? In this article, we will see how we can animate the Multi-level sidebar in ReactJS to enhance the overall appearance of the Sidebar component in the application. This attracts the user towards the interface more and also increases the look and feel of the application. We will discuss the following t
7 min read