diff --git a/frontend/src/components/Map/SearchMap/BoundsHandler.tsx b/frontend/src/components/Map/SearchMap/BoundsHandler.tsx new file mode 100644 index 000000000..b2eecdd71 --- /dev/null +++ b/frontend/src/components/Map/SearchMap/BoundsHandler.tsx @@ -0,0 +1,21 @@ +import { LatLngBounds } from 'leaflet'; +import { useEffect } from 'react'; +import { useMap } from 'react-leaflet'; + +interface Props { + bounds: LatLngBounds | null; +} + +const BoundsHandler: React.FC = ({ bounds }) => { + const map = useMap(); + + useEffect(() => { + if (bounds) { + map.fitBounds(bounds); + } + }, [bounds, map]); + + return null; +}; + +export default BoundsHandler;