"use client"; import React, { useState, useEffect, useRef } from 'react'; interface CounterProps { end: number; duration?: number; } const Counter: React.FC = ({ end, duration = 2000 }) => { const [count, setCount] = useState(0); const countRef = useRef(null); const [hasStarted, setHasStarted] = useState(false); useEffect(() => { const observer = new IntersectionObserver( ([entry]) => { if (entry.isIntersecting && !hasStarted) { setHasStarted(true); } }, { threshold: 0.1 } ); if (countRef.current) { observer.observe(countRef.current); } return () => observer.disconnect(); }, [hasStarted]); useEffect(() => { if (!hasStarted) return; let startTimestamp: number | null = null; const step = (timestamp: number) => { if (!startTimestamp) startTimestamp = timestamp; const progress = Math.min((timestamp - startTimestamp) / duration, 1); setCount(Math.floor(progress * end)); if (progress < 1) { window.requestAnimationFrame(step); } }; window.requestAnimationFrame(step); }, [hasStarted, end, duration]); return {count}; }; const counterItems = [ { icon: "/assets/imgs/icon/icon-1.png", count: 950, suffix: "k+", text: "Projects Succefull" }, { icon: "/assets/imgs/icon/icon-2.png", count: 256, suffix: "k+", text: "Happy Customers" }, { icon: "/assets/imgs/icon/icon-3.png", count: 852, suffix: "k+", text: "Consultants Planing" }, { icon: "/assets/imgs/icon/icon-4.png", count: 965, suffix: "+", text: "Awards Winners" } ]; const CounterAreaTwo: React.FC = () => { return (
    {counterItems.map((item, index) => (
  • icon

    {item.suffix}

    {item.text}

  • ))}
); }; export default CounterAreaTwo;