From a9d7188c670cdabdca0a9ffcc0e2ee10c27b92d4 Mon Sep 17 00:00:00 2001 From: Keannu Bernasol Date: Sun, 1 Oct 2023 14:32:25 +0800 Subject: [PATCH] Re-separate use effect for periodic checking and on load checking in homepage --- src/routes/Home/Home.tsx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/routes/Home/Home.tsx b/src/routes/Home/Home.tsx index c562fa5..331b6ef 100644 --- a/src/routes/Home/Home.tsx +++ b/src/routes/Home/Home.tsx @@ -82,14 +82,18 @@ export default function Home() { } } + // Refresh every 15 seconds + useEffect(() => { + const interval = setInterval(() => { + requestLocation(); + }, 15000); + + return () => clearInterval(interval); + }); + // Refresh when screen loads useEffect(() => { - // Refresh every 15 seconds - const interval = setInterval(async () => { - await requestLocation(); - }, 15000); requestLocation(); - return () => clearInterval(interval); }, []); async function DistanceHandler(location: RawLocationType) {