Last active
December 1, 2023 06:57
-
-
Save zpuckeridge/097233c5f75701a26e55f70ba6a45b7b to your computer and use it in GitHub Desktop.
Framer Motion Text Render
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "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