React Progress UI Component
rc-progress is a lightweight, performant React UI component library providing fundamental progress indicators, specifically Line and Circle progress bars. It is currently stable at version 4.0.0, released in late 2023, with maintenance releases occurring periodically as needed. The library focuses on delivering unstyled, highly customizable SVG-based progress components, allowing developers full control over styling and animation via props like `strokeWidth`, `strokeColor`, and `percent`. It differentiates itself by offering a lean API for common progress scenarios without the overhead of a full UI component suite. The library ships with TypeScript type definitions, ensuring a robust development experience, and maintains compatibility with modern React versions (>=16.9.0) while also supporting older browsers like IE9+.
Common errors
-
Module not found: Can't resolve 'rc-progress' in 'src/App.js'
cause The `rc-progress` package is not installed or incorrectly referenced.fixInstall the package using `npm install rc-progress` or `yarn add rc-progress`. Verify the import path is correct. -
TypeError: (0 , rc_progress__WEBPACK_IMPORTED_MODULE_0__.Line) is not a function
cause Attempting to use `require()` for ES Module imports or incorrect named import syntax in an ES Module context.fixEnsure you are using `import { Line, Circle } from 'rc-progress';` for ES Modules. If using CommonJS, explicitly destructure: `const { Line, Circle } = require('rc-progress');` (though ESM is preferred). -
Property 'space' does not exist on type 'IntrinsicAttributes & ProgressLineProps & RefAttributes<any>'.
cause Attempting to use the deprecated `space` prop in `rc-progress` v4.0.0 or later.fixReplace the `space` prop with `gap`. For example, change `<Line space={10} ... />` to `<Line gap={10} ... />`.
Warnings
- breaking The `space` prop has been renamed to `gap` for `Line` and `Circle` components.
- gotcha Ensure `react` and `react-dom` peer dependencies are met. The library requires `>=16.9.0`.
- gotcha While `rc-progress` supports older browsers like IE9+, ensure your overall project's browserlist and polyfills are configured correctly if targeting such environments, as the component itself relies on SVG rendering capabilities.
Install
-
npm install rc-progress -
yarn add rc-progress -
pnpm add rc-progress
Imports
- Line
const { Line } = require('rc-progress');import { Line } from 'rc-progress'; - Circle
import Circle from 'rc-progress';
import { Circle } from 'rc-progress'; - ProgressLineProps
import type { ProgressLineProps } from 'rc-progress';
Quickstart
import React, { useState, useEffect } from 'react';
import { Line, Circle } from 'rc-progress';
const ProgressDemo: React.FC = () => {
const [percent, setPercent] = useState<number>(0);
useEffect(() => {
const timer = setInterval(() => {
setPercent((prevPercent) => {
if (prevPercent >= 100) {
return 0; // Reset progress
}
return prevPercent + 10;
});
}, 500);
return () => clearInterval(timer);
}, []);
return (
<div style={{ padding: '20px', maxWidth: '400px', margin: 'auto', textAlign: 'center' }}>
<h2>Line Progress</h2>
<Line
percent={percent}
strokeWidth={4}
strokeColor={percent > 50 ? '#87d068' : '#108ee9'}
trailWidth={4}
style={{ marginBottom: '40px' }}
/>
<h2>Circle Progress</h2>
<Circle
percent={percent}
strokeWidth={6}
strokeColor={percent > 50 ? '#87d068' : '#108ee9'}
trailWidth={6}
strokeLinecap="round"
style={{ width: '150px', height: '150px' }}
/>
<p style={{ marginTop: '30px', fontSize: '1.2em', fontWeight: 'bold' }}>
Current Progress: {percent}%
</p>
</div>
);
};
export default ProgressDemo;