diff --git a/src/ui/React/CorruptableText.tsx b/src/ui/React/CorruptableText.tsx index 811fcf432..66845ccd3 100644 --- a/src/ui/React/CorruptableText.tsx +++ b/src/ui/React/CorruptableText.tsx @@ -25,20 +25,22 @@ export function CorruptableText(props: IProps): JSX.Element { useEffect(() => { let counter = 5; - const id = setInterval(() => { + const timers: number[] = []; + const intervalId = setInterval(() => { counter--; if (counter > 0) return; counter = Math.random() * 5; const index = Math.random() * content.length; const letter = content.charAt(index); setContent((content) => replace(content, index, randomize(letter))); - setTimeout(() => { + timers.push(window.setTimeout(() => { setContent((content) => replace(content, index, letter)); - }, 500); + }, 500)); }, 20); return () => { - clearInterval(id); + clearInterval(intervalId); + timers.forEach((timerId) => clearTimeout(timerId)); }; }, []);