mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-30 03:23:48 +01:00
Merge pull request #2607 from MartinFournier/fix/corruptable-unmount
Clear timers when unmounting CorruptableText
This commit is contained in:
commit
4555354957
@ -25,20 +25,22 @@ export function CorruptableText(props: IProps): JSX.Element {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let counter = 5;
|
let counter = 5;
|
||||||
const id = setInterval(() => {
|
const timers: number[] = [];
|
||||||
|
const intervalId = setInterval(() => {
|
||||||
counter--;
|
counter--;
|
||||||
if (counter > 0) return;
|
if (counter > 0) return;
|
||||||
counter = Math.random() * 5;
|
counter = Math.random() * 5;
|
||||||
const index = Math.random() * content.length;
|
const index = Math.random() * content.length;
|
||||||
const letter = content.charAt(index);
|
const letter = content.charAt(index);
|
||||||
setContent((content) => replace(content, index, randomize(letter)));
|
setContent((content) => replace(content, index, randomize(letter)));
|
||||||
setTimeout(() => {
|
timers.push(window.setTimeout(() => {
|
||||||
setContent((content) => replace(content, index, letter));
|
setContent((content) => replace(content, index, letter));
|
||||||
}, 500);
|
}, 500));
|
||||||
}, 20);
|
}, 20);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
clearInterval(id);
|
clearInterval(intervalId);
|
||||||
|
timers.forEach((timerId) => clearTimeout(timerId));
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user