Преглед на файлове

Maximum update depth exceeded fix

Viktoriia преди 13 часа
родител
ревизия
81702b44de
променени са 1 файла, в които са добавени 13 реда и са изтрити 7 реда
  1. 13 7
      src/screens/InAppScreens/MapScreen/index.tsx

+ 13 - 7
src/screens/InAppScreens/MapScreen/index.tsx

@@ -953,13 +953,20 @@ const MapScreen: any = ({ navigation, route }: { navigation: any; route: any })
 
     setIsZooming(true);
 
-    const currentZoom = await mapRef.current.getZoom();
-    setZoom(currentZoom);
+    const newZoom = await mapRef.current.getZoom();
+    const newCenter = await mapRef.current.getCenter();
 
-    if (mapRef.current) {
-      const currentCenter = await mapRef.current?.getCenter();
-      setCenter(currentCenter);
-    }
+    setZoom((prevZoom) => {
+      if (prevZoom !== newZoom) return newZoom;
+      return prevZoom;
+    });
+
+    setCenter((prevCenter) => {
+      if (!prevCenter || prevCenter[0] !== newCenter[0] || prevCenter[0] !== newCenter[0]) {
+        return newCenter;
+      }
+      return prevCenter;
+    });
   };
 
   const onMapPress = async (event: any) => {
@@ -1439,7 +1446,6 @@ const MapScreen: any = ({ navigation, route }: { navigation: any; route: any })
         attributionEnabled={false}
         onPress={onMapPress}
         onRegionDidChange={handleRegionDidChange}
-        onRegionIsChanging={handleMapChange}
         onRegionWillChange={_.debounce(handleMapChange, 200)}
         onDidFinishLoadingStyle={() => setDidFinishLoadingStyle(true)}
       >