diff --git a/src/components/MapView/MapView.tsx b/src/components/MapView/MapView.tsx index ac1af8d4d727..f7a15ba10d2c 100644 --- a/src/components/MapView/MapView.tsx +++ b/src/components/MapView/MapView.tsx @@ -31,15 +31,6 @@ const MapView = forwardRef( const [userInteractedWithMap, setUserInteractedWithMap] = useState(false); const hasAskedForLocationPermission = useRef(false); - const getUserLocationFromCache = useCallback(() => { - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - if (cachedUserLocation || !initialState) { - return; - } - - setCurrentPosition({longitude: initialState.location[0], latitude: initialState.location[1]}); - }, [cachedUserLocation, initialState]); - useFocusEffect( useCallback(() => { if (isOffline) { @@ -47,17 +38,26 @@ const MapView = forwardRef( } if (hasAskedForLocationPermission.current) { - getUserLocationFromCache(); return; } hasAskedForLocationPermission.current = true; - getCurrentPosition((params) => { - const currentCoords = {longitude: params.coords.longitude, latitude: params.coords.latitude}; - setCurrentPosition(currentCoords); - setUserLocation(currentCoords); - }, getUserLocationFromCache); - }, [getUserLocationFromCache, isOffline]), + getCurrentPosition( + (params) => { + const currentCoords = {longitude: params.coords.longitude, latitude: params.coords.latitude}; + setCurrentPosition(currentCoords); + setUserLocation(currentCoords); + }, + () => { + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + if (cachedUserLocation || !initialState) { + return; + } + + setCurrentPosition({longitude: initialState.location[0], latitude: initialState.location[1]}); + }, + ); + }, [cachedUserLocation, initialState, isOffline]), ); // Determines if map can be panned to user's detected diff --git a/src/components/MapView/MapView.website.tsx b/src/components/MapView/MapView.website.tsx index 81ad13696778..9ade3548f959 100644 --- a/src/components/MapView/MapView.website.tsx +++ b/src/components/MapView/MapView.website.tsx @@ -54,15 +54,6 @@ const MapView = forwardRef( const setRef = useCallback((newRef: MapRef | null) => setMapRef(newRef), []); const hasAskedForLocationPermission = useRef(false); - const getUserLocationFromCache = useCallback(() => { - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - if (cachedUserLocation || !initialState) { - return; - } - - setCurrentPosition({longitude: initialState.location[0], latitude: initialState.location[1]}); - }, [cachedUserLocation, initialState]); - useFocusEffect( useCallback(() => { if (isOffline) { @@ -70,17 +61,26 @@ const MapView = forwardRef( } if (hasAskedForLocationPermission.current) { - getUserLocationFromCache(); return; } hasAskedForLocationPermission.current = true; - getCurrentPosition((params) => { - const currentCoords = {longitude: params.coords.longitude, latitude: params.coords.latitude}; - setCurrentPosition(currentCoords); - setUserLocation(currentCoords); - }, getUserLocationFromCache); - }, [getUserLocationFromCache, isOffline]), + getCurrentPosition( + (params) => { + const currentCoords = {longitude: params.coords.longitude, latitude: params.coords.latitude}; + setCurrentPosition(currentCoords); + setUserLocation(currentCoords); + }, + () => { + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + if (cachedUserLocation || !initialState) { + return; + } + + setCurrentPosition({longitude: initialState.location[0], latitude: initialState.location[1]}); + }, + ); + }, [cachedUserLocation, initialState, isOffline]), ); // Determines if map can be panned to user's detected