import { useMap, useMapsLibrary } from '@vis.gl/react-google-maps';
import { useEffect, useState } from 'react';
export function useDrawingManager(initialValue: google.maps.drawing.DrawingManager | null = null) {
const map = useMap();
const drawing = useMapsLibrary('drawing');
const [drawingManager, setDrawingManager] = useState<google.maps.drawing.DrawingManager | null>(initialValue);
useEffect(() => {
if (!map || !drawing) return;
const newDrawingManager = new drawing.DrawingManager({
map,
drawingMode: google.maps.drawing.OverlayType.POLYGON,
drawingControl: true,
drawingControlOptions: {
position: google.maps.ControlPosition.TOP_CENTER,
drawingModes: [google.maps.drawing.OverlayType.POLYGON]
},
polygonOptions: {
editable: true,
draggable: true
}
});
setDrawingManager(newDrawingManager);
return () => {
newDrawingManager.setMap(null);
};
}, [drawing, map]);
return drawingManager;
}
I am encountering error in the return function of useEffect()
.