'use client'; import Image from 'next/image'; import React, { useEffect, useRef, useState } from 'react'; import SlotCounter, { SlotCounterRef } from 'react-slot-counter'; import { useMediaQuery } from 'usehooks-ts'; interface LotterySlotCounterProps { numberString: string; } const LotterySlotCounter = ({ numberString }: LotterySlotCounterProps) => { const [formattedNumber, setFormattedNumber] = useState(numberString); const slotCounterRef = useRef(null); // Ref for manual control const isFirstRender = useRef(true); // Ref to track the initial render const tablet = useMediaQuery('(max-width: 769px)'); const mobile = useMediaQuery('(max-width: 426px)'); useEffect(() => { const formatted = numberString.replace(/-/g, ','); setFormattedNumber(formatted); // Skip animation on the first render if (isFirstRender.current) { isFirstRender.current = false; // Mark as no longer the first render return; } // Trigger animation manually when numberString changes if (slotCounterRef.current) { slotCounterRef.current.startAnimation(); } }, [numberString]); return (
{mobile ? ( roller-triangle ) : ( roller-triangle )} {mobile ? ( roller-triangle ) : ( roller-triangle )}
{/* Highlight */}
); }; export default LotterySlotCounter;