Skip to content
Snippets Groups Projects
Verified Commit 80902a2b authored by João Magalhães's avatar João Magalhães :rocket:
Browse files

fix: interval garbage collection

parent ddcad418
No related branches found
No related tags found
1 merge request!12Version 0.4.1
Pipeline #1431 passed
import React, { FC } from "react";
import React, { FC, useEffect, useRef } from "react";
import { PixelFormat } from "../../app";
import Canvas, { CanvasStructure } from "../canvas/canvas";
......@@ -18,6 +18,14 @@ export const Tiles: FC<TilesProps> = ({
style = []
}) => {
const classes = () => ["tiles", ...style].join(" ");
const intervalsRef = useRef<number>();
useEffect(() => {
return () => {
if (intervalsRef.current) {
clearInterval(intervalsRef.current);
}
};
}, []);
const onCanvas = (structure: CanvasStructure) => {
const drawTiles = () => {
for (let index = 0; index < 384; index++) {
......@@ -26,7 +34,7 @@ export const Tiles: FC<TilesProps> = ({
}
};
drawTiles();
setInterval(() => drawTiles(), interval);
intervalsRef.current = setInterval(() => drawTiles(), interval);
};
return (
<div className={classes()}>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment