-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoading.tsx
39 lines (31 loc) · 947 Bytes
/
Loading.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import React, { useState, useEffect } from 'react';
import { Progress } from 'antd';
import 'antd/dist/antd.css';
import './LoadingProgressBar.css';
function LoadingProgressBar() {
const [percent, setPercent] = useState(0);
useEffect(() => {
let animationFrameId;
let currentPercent = 0;
const animate = () => {
currentPercent += 1;
setPercent(prevPercent => {
const newPercent = currentPercent > 100 ? 100 : currentPercent;
return newPercent;
});
if (currentPercent <= 100) {
animationFrameId = requestAnimationFrame(animate);
}
};
animationFrameId = requestAnimationFrame(animate);
return () => {
cancelAnimationFrame(animationFrameId);
};
}, []);
return (
<div className="loading-progress-bar">
<Progress type="line" percent={percent} strokeWidth={4} strokeLinecap="square" />
</div>
);
}
export default LoadingProgressBar;