Skip to content

Instantly share code, notes, and snippets.

@zpuckeridge
Last active December 1, 2023 06:57
Show Gist options
  • Select an option

  • Save zpuckeridge/097233c5f75701a26e55f70ba6a45b7b to your computer and use it in GitHub Desktop.

Select an option

Save zpuckeridge/097233c5f75701a26e55f70ba6a45b7b to your computer and use it in GitHub Desktop.
Framer Motion Text Render
"use client";
import { useEffect } from "react";
import { motion, stagger, useAnimate } from "framer-motion";
export const TextGenerateEffect: React.FC<{ words: string }> = ({ words }) => {
const wordsArray = words.split(" ");
const [scope, animate] = useAnimate();
useEffect(() => {
animate(
"span",
{
opacity: 1,
},
{
duration: 1,
delay: stagger(0.2),
}
);
}, [animate]);
const renderWords = () => {
return (
<motion.div ref={scope}>
{wordsArray.map((word) => {
return (
<motion.span key={word} className="text-white opacity-0">
{word}{" "}
</motion.span>
);
})}
</motion.div>
);
};
return (
<div className="text-white text-2xl leading-snug">{renderWords()}</div>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment