Skip to content

Commit

Permalink
Create BoundsHandler component
Browse files Browse the repository at this point in the history
  • Loading branch information
dtrucs committed Oct 17, 2024
1 parent e0d8684 commit b937dec
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions frontend/src/components/Map/SearchMap/BoundsHandler.tsx
Original file line number Diff line number Diff line change
@@ -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<Props> = ({ bounds }) => {
const map = useMap();

useEffect(() => {
if (bounds) {
map.fitBounds(bounds);
}
}, [bounds, map]);

return null;
};

export default BoundsHandler;

0 comments on commit b937dec

Please sign in to comment.