"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; startNumber: string; } const LotterySlotCounter = ({ numberString, startNumber, }: LotterySlotCounterProps) => { const [formattedNumber, setFormattedNumber] = useState("00,00,00,00,00"); const slotCounterRef = useRef(null); // Ref for manual control const isFirstRender = useRef(true); // Ref to track the initial render 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;