import React, { useEffect, useState, useRef } from 'react' import useReveal from '../hooks/useReveal' function Counter({ end, suffix = '', duration = 2000 }) { const [count, setCount] = useState(0) const ref = useRef(null) const started = useRef(false) useEffect(() => { const observer = new IntersectionObserver( ([entry]) => { if (entry.isIntersecting && !started.current) { started.current = true const step = end / (duration / 16) let current = 0 const timer = setInterval(() => { current += step if (current >= end) { setCount(end) clearInterval(timer) } else { setCount(Math.floor(current)) } }, 16) } }, { threshold: 0.5 } ) if (ref.current) observer.observe(ref.current) return () => observer.disconnect() }, [end, duration]) return ( {count.toLocaleString()}{suffix} ) } const stats = [ { value: 40, suffix: '', label: 'Days to Transform', color: 'text-nova-primary' }, { value: 5, suffix: '', label: 'Daily Habits', color: 'text-nova-accent' }, { value: 40, suffix: '+', label: 'Days of History', color: 'text-nova-warning' }, { value: 100, suffix: '%', label: 'Free to Use', color: 'text-nova-success' }, ] export default function Stats() { const ref = useReveal() return ( {stats.map((stat, i) => ( {stat.label} ))} ) }
{stat.label}