Przeglądaj źródła

Moving the useMap hook out to shared dir

Kirk Trombley 5 lat temu
rodzic
commit
bc694b86aa

+ 1 - 20
client/src/components/screens/GamePanel/ClickMarkerMap.jsx

@@ -1,26 +1,7 @@
 import React, { useRef, useEffect } from "react";
+import useMap from "../../../hooks/useMap";
 /* global google */
 
-const useMap = () => {
-  const mapDiv = useRef(null);
-  const map = useRef(null);
-  useEffect(() => {
-    if (map.current) {
-      console.log("Attempted to re-run effect with existing Map");
-      return;
-    }
-    
-    map.current = new google.maps.Map(mapDiv.current, {
-      center: { lat: 25, lng: -25 },
-      zoom: 0,
-      disableDefaultUI: true,
-      fullscreenControl: true,
-    });
-  }, []);
-
-  return [mapDiv, map];
-}
-
 const useClickMarker = (map, onMove) => {
   const marker = useRef(null);
   useEffect(() => {

+ 22 - 0
client/src/hooks/useMap.jsx

@@ -0,0 +1,22 @@
+import { useRef, useEffect } from "react";
+/* global google */
+
+export default () => {
+  const mapDiv = useRef(null);
+  const map = useRef(null);
+  useEffect(() => {
+    if (map.current) {
+      console.log("Attempted to re-run effect with existing Map");
+      return;
+    }
+    
+    map.current = new google.maps.Map(mapDiv.current, {
+      center: { lat: 25, lng: -25 },
+      zoom: 0,
+      disableDefaultUI: true,
+      fullscreenControl: true,
+    });
+  }, []);
+
+  return [mapDiv, map];
+}