Initial commit
This commit is contained in:
20
src_frontend_orig/components/CountUp.jsx
Normal file
20
src_frontend_orig/components/CountUp.jsx
Normal file
@@ -0,0 +1,20 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
|
||||
export function CountUp({ value }) {
|
||||
const [v, setV] = useState(0);
|
||||
useEffect(() => {
|
||||
const start = v;
|
||||
const end = value;
|
||||
const dur = 600;
|
||||
const t0 = performance.now();
|
||||
let raf;
|
||||
const step = (t) => {
|
||||
const p = Math.min(1, (t - t0) / dur);
|
||||
setV(Math.round(start + (end - start) * p));
|
||||
if (p < 1) raf = requestAnimationFrame(step);
|
||||
};
|
||||
raf = requestAnimationFrame(step);
|
||||
return () => cancelAnimationFrame(raf);
|
||||
}, [value]);
|
||||
return <span>{v}</span>;
|
||||
}
|
||||
Reference in New Issue
Block a user