Created
June 8, 2020 20:15
-
-
Save nestarz/52f567792cd0f35cb9621452717de74c to your computer and use it in GitHub Desktop.
TextSequence
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
export const TextSequence = ({ | |
texts = ["ceci", 1000, "est", 1000, "une", 1000, "demo", 1000], | |
}) => { | |
const [text, setText] = useState(); | |
useEffect(() => { | |
setTimeout(function update(i = 0) { | |
const data = texts[i % texts.length]; | |
if (typeof data === "string") setText(data); | |
setTimeout(() => update(i + 1), typeof data === "number" ? data : 0); | |
}); | |
}, []); | |
return text; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment