Skip to content

Commit

Permalink
extracting resizeObserver into antoher useEffect.
Browse files Browse the repository at this point in the history
  • Loading branch information
nahid633 committed Sep 18, 2023
1 parent db324f0 commit e83f20f
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/components/MapView/MapView.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,24 @@ const MapView = forwardRef<MapViewHandle, MapViewProps>(

const map = mapRef.getMap();

const resizeObserver = new ResizeObserver(() => {
mapRef?.resize();
});
resizeObserver.observe(mapRef?.getContainer());

const {northEast, southWest} = utils.getBounds(waypoints.map((waypoint) => waypoint.coordinate));
map.fitBounds([northEast, southWest], {padding: mapPadding});
}, [waypoints, mapRef, mapPadding]);

useEffect(() => {
if (!mapRef) {
return;
}

const resizeObserver = new ResizeObserver(() => {
mapRef.resize();
});
resizeObserver.observe(mapRef.getContainer());

return () => {
resizeObserver?.disconnect();
}
}, [waypoints, mapRef, mapPadding]);
}, [mapRef]);

useImperativeHandle(
ref,
Expand Down

0 comments on commit e83f20f

Please sign in to comment.