From 76300209f19f9d4c0ad5f9b575b6cad2f4a86b36 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Fri, 10 Apr 2020 12:49:09 -0700 Subject: [PATCH] Correctly clear the interval for resource use checking --- resources/scripts/components/dashboard/ServerRow.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/resources/scripts/components/dashboard/ServerRow.tsx b/resources/scripts/components/dashboard/ServerRow.tsx index 7789f8125..9903ec17f 100644 --- a/resources/scripts/components/dashboard/ServerRow.tsx +++ b/resources/scripts/components/dashboard/ServerRow.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from 'react'; +import React, { useEffect, useRef, useState } from 'react'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faServer } from '@fortawesome/free-solid-svg-icons/faServer'; import { faEthernet } from '@fortawesome/free-solid-svg-icons/faEthernet'; @@ -21,18 +21,19 @@ const isAlarmState = (current: number, limit: number): boolean => { }; export default ({ server, className }: { server: Server; className: string | undefined }) => { + const interval = useRef(null); const [ stats, setStats ] = useState(null); const getStats = () => getServerResourceUsage(server.uuid).then(data => setStats(data)); useEffect(() => { - let interval: any = null; getStats().then(() => { - interval = setInterval(() => getStats(), 20000); + // @ts-ignore + interval.current = setInterval(() => getStats(), 20000); }); return () => { - interval && clearInterval(interval); + interval.current && clearInterval(interval.current); }; }, []);