import { useMapEvent } from 'react-leaflet';
import { LatLngLiteral } from 'leaflet';

interface IChangeHandlerProps {
	onChange?: (value: LatLngLiteral) => void;
}

const ChangeOnMoveHandler = ({ onChange }: IChangeHandlerProps) => {
	useMapEvent('moveend', (evt) => {
		onChange?.(evt.target.getCenter() as LatLngLiteral);
	});

	return null;
};

export default ChangeOnMoveHandler;
