Spaces:
Sleeping
Sleeping
File size: 581 Bytes
05c5ed5 | 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 | "use client";
import { cn } from "@/lib/utils";
import { motion, useMotionValue, useTransform, animate } from "framer-motion";
import { useEffect } from "react";
function CountAnimation({
number,
className,
}: {
number: number;
className?: string;
}) {
const count = useMotionValue(0);
const rounded = useTransform(count, Math.round);
useEffect(() => {
const animation = animate(count, number, { duration: 1 });
return animation.stop;
}, [number]);
return <motion.span className={cn(className)}>{rounded}</motion.span>;
}
export { CountAnimation };
|