To create interactive UI elements like feature cards or status banners, you can trigger an AnimateIcon animation based on the hover state of its parent container.
Instead of triggering the animation on the icon itself, use a useRef hook to capture the icon's handle (e.g., SparklesIconHandle) and call .startAnimation() and .stopAnimation() within the container's onMouseEnter and onMouseLeave event handlers. This makes the entire surface area of the container the trigger for the animation.
import { useRef } from "react"
import { SparklesIcon, type SparklesIconHandle } from "@animateicons/react/lucide"
export function FeatureCard() {
const ref = useRef<SparklesIconHandle>(null)
return (
<div
onMouseEnter={() => ref.current?.startAnimation()}
onMouseLeave={() => ref.current?.stopAnimation()}
className="rounded-xl border p-5"
>
<SparklesIcon ref={ref} size={20} />
<p>Smart suggestions</p>
</div>
)
}