🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
'use client';
import { memo, useEffect, useRef, useState } from 'react';
interface AnimatedNumberProps {
duration?: number;
formatter?: (value: number) => string;
value: number;
}
export const AnimatedNumber = memo<AnimatedNumberProps>(({ value, duration = 500, formatter }) => {
const [displayValue, setDisplayValue] = useState(value);
const frameRef = useRef<number>(undefined);
const startTimeRef = useRef<number>(undefined);
const startValueRef = useRef(value);
useEffect(() => {
const startValue = startValueRef.current;
const diff = value - startValue;
if (diff === 0) return;
const animate = (currentTime: number) => {
if (!startTimeRef.current) {
startTimeRef.current = currentTime;
}
const elapsed = currentTime - startTimeRef.current;
const progress = Math.min(elapsed / duration, 1);
// easeOutCubic
const easeProgress = 1 - (1 - progress) ** 3;
const current = startValue + diff * easeProgress;
setDisplayValue(current);
if (progress < 1) {
frameRef.current = requestAnimationFrame(animate);
} else {
startValueRef.current = value;
startTimeRef.current = undefined;
}
};
frameRef.current = requestAnimationFrame(animate);
return () => {
if (frameRef.current) {
cancelAnimationFrame(frameRef.current);
}
};
}, [value, duration]);
return formatter ? formatter(displayValue) : Math.round(displayValue).toLocaleString();
});
AnimatedNumber.displayName = 'AnimatedNumber';