Clue Mediator

How to implement a circular progress bar in React

๐Ÿ“…December 20, 2021
๐Ÿ—ReactJS

Today we will show you how to implement a circular progress bar in React application. Here we will use the NPM Package to implement the circular progress bar.

Checkout more articles on ReactJS

Demo Application

Output - How to implement a circular progress bar in React - Clue Mediator

Output - How to implement a circular progress bar in React - Clue Mediator

Steps to add a circular progress bar in React

  1. Install npm package
  2. Implement a circular progress bar
  3. Output

1. Install npm package

Letโ€™s create a react application and install the react-circular-progressbar npm package. Run the following command to install the package.

npm i react-circular-progressbar

2. Implement a circular progress bar

To add a circular progress bar in the react component, we have to import the package and CSS at the top of the page.

import { CircularProgressbar } from 'react-circular-progressbar';
import 'react-circular-progressbar/dist/styles.css';

Need to add the following code to render the circular progress bar.

const percentage = 66;
<circularprogressbar value={percentage} text={`${percentage}%`}>
</circularprogressbar>

Let's add code to the component and gradually increase the percentage and see how it looks.

App.js

import React, { useEffect, useState } from 'react';
import { CircularProgressbar } from 'react-circular-progressbar';
import 'react-circular-progressbar/dist/styles.css';

function App() {
  const [percentage, setPercentage] = useState(0);

  useEffect(() => {
    setTimeout(() => {
      if (percentage < 100) {
        setPercentage(percentage + 1);
      }
    }, 50);
  }, [percentage]);

  return (
    <div class="app">
      <h4>Circular progress bar in React - <a href="https://www.cluemediator.com" target="_blank" rel="noopener">Clue Mediator</a></h4>
      <div 70="" style={{ width: 150, marginleft: }}>
        <circularprogressbar value={percentage} text={`${percentage}%`}>
      </circularprogressbar></div>
    </div>
  );
}

export default App;

3. Output

Run the react application and check the output in the browser.

I hope you find this article helpful.
Thank you for reading. Happy Coding..!! ๐Ÿ™‚

Demo & Source Code

GitHub Repository StackBlitz Project