Skip to content

Instantly share code, notes, and snippets.

@nestarz
Created June 8, 2020 20:15
Show Gist options
  • Save nestarz/52f567792cd0f35cb9621452717de74c to your computer and use it in GitHub Desktop.
Save nestarz/52f567792cd0f35cb9621452717de74c to your computer and use it in GitHub Desktop.
TextSequence
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