Skip to content
Related Articles

Related Articles

How to use CircularProgress Component in ReactJS?

View Discussion
Improve Article
Save Article
  • Last Updated : 22 Jan, 2021

As we know that progress indicators inform users about the status of ongoing processes such as loading an app, uploading data, etc. We can use CircularProgress Component in ReactJS to show this circular loading effect. Material UI for React has this component available for us and it is very easy to integrate. 

Creating React Application And Installing Module:

Step 1: Create a React application using the following command:

npx create-react-app foldername

Step 2: After creating your project folder i.e. foldername, move to it using the following command:

cd foldername

Step 3: After creating the ReactJS application, Install the material-ui modules using the following command:

npm install @material-ui/core

Project Structure: It will look like the following.

Project Structure

App.js: Now write down the following code in the App.js file. Here, App is our default component where we have written our code.


import React, {useEffect, useState} from 'react';
import CircularProgress from '@material-ui/core/CircularProgress';
const App = () => {
  useEffect(()=> {
  }, [])
  const [isLoading, setIsLoading] = useState(true)
  // Sample API to fetch Data
  const getDataFromAPI = () => {
    console.log("API called!!")
     .then((response) => {
      return response.json()
    }).then((res) => {
      }, 2000)
  return (
    <div style={{
      marginLeft: '40%',
      <h2>How to use CircularProgress Component in ReactJS?</h2>
      {isLoading && <CircularProgress color="secondary" />} 
      {!isLoading && <h3>Successfully API Loaded Data</h3>}
export default App;

Step to Run Application: Run the application using the following command from the root directory of the project:

npm start

Output: Now open your browser and go to http://localhost:3000/, you will see the following output:

This is how we can show the loading effect in ReactJS using the CircularProgress component.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!