import { Map } from "leaflet";
import { FC, useEffect } from "react";
import { useMap } from "react-leaflet";

let instance: Map | undefined;

export const MapExplorer: FC = () => {
	const map = useMap();

	useEffect(() => {
		instance = map;
	}, [map]);

	useEffect(() => {
		if (instance) {
			instance.invalidateSize();
		}
	}, []);

	return null;
};

export const useAppMap = (): (() => Map | undefined) => {
	return () => instance;
};
