import React, { useState, useEffect, useRef } from 'react'; import { motion } from 'framer-motion'; const random = (min, max) => Math.random() * (max - min) + min; const Particle = ({ id, color, size, duration }) => { const angle = random(0, Math.PI * 2); const radius = random(40, 85); // How far particles travel (Increased) const endX = Math.cos(angle) * radius; const endY = Math.sin(angle) * radius; return ( ); }; const ButtonParticles = ({ trigger, color = '#ffffff', count = 8, size = 3.5, duration = 0.45 }) => { const [particles, setParticles] = useState([]); console.log(`ButtonParticles: Rendered. Current trigger=${trigger}, particles=${particles.length}`); useEffect(() => { console.log(`ButtonParticles: useEffect triggered. trigger=${trigger}`); if (trigger > 0) { // trigger increments on each click console.log(`ButtonParticles: Trigger > 0 (${trigger}). Generating ${count} particles.`); const newParticles = Array.from({ length: count }).map((_, i) => ({ id: `${trigger}-${i}`, // Unique key based on trigger and index color, size, duration, })); setParticles(newParticles); console.log("ButtonParticles: Particles state updated:", newParticles); // Optional: Clear particles after animation - not strictly needed as they animate to opacity 0 const timer = setTimeout(() => { console.log(`ButtonParticles: Clearing particles after ${duration}s timeout.`); setParticles([]); }, duration * 1000); // Clear particles after animation return () => { console.log("ButtonParticles: useEffect cleanup running."); clearTimeout(timer) }; } }, [trigger, color, count, size, duration]); // Render only the particles currently animating return ( <> {particles.map(p => ( {/* Use Fragment to add log without extra div */} {/* {console.log(`ButtonParticles: Rendering Particle id=${p.id}`)} */} ))} ); }; export default ButtonParticles;