Skip to content

Commit

Permalink
Refactor AnimatedCounter component for improved readability
Browse files Browse the repository at this point in the history
- Changed variable declarations from `let` to `const` for `valueRoundedToPlace`, `animatedValue`, `y`, `placeValue`, and `offset` to enhance code clarity and maintainability.
- Updated array mapping method in the `Digit` component to use `Array.from` for better readability.
- Minor formatting adjustments for consistency across the component.
  • Loading branch information
aliirz committed Jan 17, 2025
1 parent 2309d92 commit 9992a75
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions components/ui/animated-counter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,26 @@ export function AnimatedCounter({ value }: { value: number }) {
}

function Digit({ place, value }: { place: number; value: number }) {
let valueRoundedToPlace = Math.floor(value / place);
let animatedValue = useSpring(valueRoundedToPlace);
const valueRoundedToPlace = Math.floor(value / place);
const animatedValue = useSpring(valueRoundedToPlace);

useEffect(() => {
animatedValue.set(valueRoundedToPlace);
}, [animatedValue, valueRoundedToPlace]);

return (
<div style={{ height }} className="relative w-[1ch] tabular-nums">
{[...Array(10).keys()].map((i) => (
{Array.from({ length: 10 }, (_, i) => (
<Number key={i} mv={animatedValue} number={i} />
))}
</div>
);
}

function Number({ mv, number }: { mv: MotionValue; number: number }) {
let y = useTransform(mv, (latest) => {
let placeValue = latest % 10;
let offset = (10 + number - placeValue) % 10;
const y = useTransform(mv, (latest) => {
const placeValue = latest % 10;
const offset = (10 + number - placeValue) % 10;
let memo = offset * height;
if (offset > 5) {
memo -= 10 * height;
Expand Down

0 comments on commit 9992a75

Please sign in to comment.