Counter Animation
Counter Animation is a React and Tailwind CSS text component from Bund UI, licensed MIT. Copy it and paste it into your project.
Bund UI
MIT
text
What it is
Counter Animation is a React and Tailwind CSS text component from Bund UI, licensed MIT. Copy it and paste it into your project.
How to use it
Open it in the catalogue, press copy, and paste it into your project. The prompt you copy carries the code and the rules that tell your agent to reproduce it without changing anything.
Five free copies a month. No card.
Needs
npm i motion
Licence
This component comes from Bund UI and is redistributed under the MIT licence, which permits commercial use. The copyright notice travels with the code.
Counter Animation
"use client";
import React from "react";
import { cn } from "@/lib/utils";
import { useMotionValue, useTransform, animate, useMotionValueEvent } from "motion/react";
type Props = {
number: number;
className?: string;
prefix?: string;
suffix?: string;
};
export default function CounterAnimation({ number, className, prefix, suffix }: Props) {
const count = useMotionValue(0);
const rounded = useTransform(count, Math.round);
const [current, setCurrent] = React.useState(0);
React.useEffect(() => {
const animation = animate(count, number, { duration: 2 });
return animation.stop;
}, [count, number]);
useMotionValueEvent(rounded, "change", (latest) => {
setCurrent(latest);
});
return (
<span className={cn(className)}>
{prefix}
{current}
{suffix}
</span>
);
}
import CounterAnimation from "./counter-animation";
export default function CounterExample() {
return <CounterAnimation number={60} className="text-2xl font-semibold lg:text-5xl" />;
}