From feab2925491ce7bd77c11432a87294db17632b92 Mon Sep 17 00:00:00 2001 From: kvebers Date: Sun, 14 Apr 2024 19:10:48 +0200 Subject: [PATCH] Clean Up Of Performance Issues --- frontend/src/pages/Games/Tournament.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frontend/src/pages/Games/Tournament.js b/frontend/src/pages/Games/Tournament.js index a15f7b33..2c9ccd8b 100644 --- a/frontend/src/pages/Games/Tournament.js +++ b/frontend/src/pages/Games/Tournament.js @@ -938,7 +938,7 @@ const Tournament = () => { ); } - + const interval = useRef(null); useEffect(() => { if (pageToRender === 3) { const canvas = canvasRef.current; @@ -957,7 +957,7 @@ const Tournament = () => { // eslint-disable-next-line react-hooks/exhaustive-deps scorePlayer2 = 0; ctxRef.current = ctx; - const interval = setInterval(() => update(canvas, ctx), 1000 / 30); + interval.current = setInterval(() => update(canvas, ctx), 1000 / 30); return () => clearInterval(interval); } // eslint-disable-next-line react-hooks/exhaustive-deps @@ -1031,6 +1031,7 @@ const Tournament = () => { if (scorePlayer1 >= 2 || scorePlayer2 >= 2) { ballSpeed = 0; updateResults(); + clearInterval(interval.current); if (tournament.matches.length !== 0) setPageToRender(2); else setPageToRender(4); }