Re-separate use effect for periodic checking and on load checking in homepage

This commit is contained in:
Keannu Bernasol 2023-10-01 14:32:25 +08:00
parent d072ae456d
commit a9d7188c67

View file

@ -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) {