From 945a11bb644de0aafa749c65e2cdcfc487d99c92 Mon Sep 17 00:00:00 2001 From: ISA Date: Wed, 19 Jun 2024 10:08:27 +0200 Subject: [PATCH] feat: Trigger second useEffect after fetching poiData - Updated the first useEffect to fetch POI data from the API and store it in state. - Added poiData as a dependency to the second useEffect to ensure it runs only after poiData is fetched. - Ensured that the second useEffect waits for poiData to be populated before processing locations and adding markers to the map. This change guarantees that the markers are only processed and displayed once the necessary POI data is available. --- components/MapComponent.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/components/MapComponent.js b/components/MapComponent.js index 2cd31ecb6..1a013a4e2 100644 --- a/components/MapComponent.js +++ b/components/MapComponent.js @@ -1211,6 +1211,8 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { }, []); //-------------------------------------------- useEffect(() => { + if (poiData.length === 0) return; + try { if (map && poiLayerRef.current && isPoiTypLoaded) { map.removeLayer(poiLayerRef.current); @@ -1306,6 +1308,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { isPoiTypLoaded, userRights, poiLayerVisible, + poiData, // Add poiData as a dependency ]); //---------------------------------------------