fix: define and initialize setSelectedArea to avoid ReferenceError
- Imported useSetRecoilState from Recoil - Defined and initialized setSelectedArea using useSetRecoilState with selectedAreaState - Ensured setSelectedArea is used to reset the selected area after moving the map This resolves the ReferenceError: setSelectedArea is not defined.
This commit is contained in:
@@ -698,6 +698,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
||||
//------------------------------------------
|
||||
//------------------------------------------ */
|
||||
const selectedArea = useRecoilValue(selectedAreaState);
|
||||
const setSelectedArea = useSetRecoilState(selectedAreaState);
|
||||
|
||||
// Combine all markers into a single array
|
||||
const allMarkers = [
|
||||
@@ -2038,15 +2039,26 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
||||
//------------------------------------------ */
|
||||
|
||||
// Effect to handle navigation to selected area
|
||||
useEffect(() => {
|
||||
/* useEffect(() => {
|
||||
if (selectedArea && map) {
|
||||
const marker = findMyMarker(selectedArea);
|
||||
if (marker) {
|
||||
map.flyTo(marker.getLatLng(), 14); // Adjust zoom level as needed
|
||||
}
|
||||
}
|
||||
}, [selectedArea, map, allMarkers]); // Include allMarkers in the dependencies
|
||||
}, [selectedArea, map, allMarkers]); // Include allMarkers in the dependencies */
|
||||
|
||||
useEffect(() => {
|
||||
if (selectedArea && map) {
|
||||
const marker = findMyMarker(selectedArea);
|
||||
if (marker) {
|
||||
map.flyTo(marker.getLatLng(), 14);
|
||||
map.once("moveend", () => {
|
||||
setSelectedArea("Station wählen");
|
||||
});
|
||||
}
|
||||
}
|
||||
}, [selectedArea, map]);
|
||||
//------------------------------------------
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user