"use client"; import { useEffect } from "react"; import { motion, stagger, useAnimate, useInView } from "framer-motion"; import { cn } from "@/lib/utils"; import { useRef } from "react"; export const TextGenerateEffect = ({ words, className, filter = true, duration = 1, }: { words: string; className?: string; filter?: boolean; duration?: number; }) => { const [scope, animate] = useAnimate(); const containerRef = useRef(null); const isInView = useInView(containerRef, { once: true }); let wordsArray = words.split(" "); useEffect(() => { if (isInView) { animate( "span", { opacity: 1, filter: filter ? "blur(0px)" : "none", }, { duration: duration ? duration : 1, delay: stagger(0.2), ease: "easeOut", // added an ease for smoother animation } ); } }, [isInView, scope.current, animate, filter, duration]); const renderWords = () => { return ( <> {wordsArray.map((word, idx) => { return ( {word}{" "} ); })} ); }; return (
{renderWords()}
); };