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

Moving hook into separate file

Kirk Trombley преди 5 години
родител
ревизия
d7b04c3701
променени са 2 файла, в които са добавени 19 реда и са изтрити 17 реда
  1. 2 17
      client/src/components/screens/GamePanel/ClickMarkerMap.jsx
  2. 17 0
      client/src/components/screens/GamePanel/useClickMarker.jsx

+ 2 - 17
client/src/components/screens/GamePanel/ClickMarkerMap.jsx

@@ -1,21 +1,6 @@
-import React, { useRef, useEffect } from "react";
+import React, { useRef } from "react";
 import useMap from "../../../hooks/useMap";
-/* global google */
-
-const useClickMarker = (map, onMove) => {
-  const marker = useRef(null);
-  useEffect(() => {
-    const listener = map.current.addListener("click", ({ latLng }) => {
-      if (marker.current) {
-        marker.current.setMap(null);
-      }
-      marker.current = new google.maps.Marker({ map: map.current, position: latLng });
-      onMove({ lat: latLng.lat(), lng: latLng.lng() });
-    });
-
-    return () => { google.maps.event.removeListener(listener); }
-  }, [map, onMove]);
-}
+import useClickMarker from "./useClickMarker";
 
 export default ({ onMarkerMoved }) => {
   const mapDivRef = useRef(null);

+ 17 - 0
client/src/components/screens/GamePanel/useClickMarker.jsx

@@ -0,0 +1,17 @@
+import { useRef, useEffect } from "react";
+/* global google */
+
+export default (map, onMove) => {
+  const marker = useRef(null);
+  useEffect(() => {
+    const listener = map.current.addListener("click", ({ latLng }) => {
+      if (marker.current) {
+        marker.current.setMap(null);
+      }
+      marker.current = new google.maps.Marker({ map: map.current, position: latLng });
+      onMove({ lat: latLng.lat(), lng: latLng.lng() });
+    });
+
+    return () => { google.maps.event.removeListener(listener); }
+  }, [map, onMove]);
+}