From 0dfcf710c8dee1b5ac6ea52e19b996eaaa548c7c Mon Sep 17 00:00:00 2001 From: Alex Lanz Date: Tue, 14 Sep 2021 12:32:50 +0200 Subject: [PATCH] Optimized location provider --- src/location-provider/LocationProvider.tsx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/location-provider/LocationProvider.tsx b/src/location-provider/LocationProvider.tsx index 470611b..a76b31f 100644 --- a/src/location-provider/LocationProvider.tsx +++ b/src/location-provider/LocationProvider.tsx @@ -19,11 +19,14 @@ export const LocationProvider: React.FC<{ location: null, }) - const updateLocation = async () => { - const position = await getCurrentLocation(highAccuracy).catch( - () => location.location - ) - setLocation({ location: position }) + const updateLocation = () => { + getCurrentLocation(highAccuracy) + .then((position) => { + setLocation({ location: position }) + }) + .catch(() => { + setLocation({ location: null }) + }) } useEffect(() => {