Move error handling to separate effect
This commit is contained in:
parent
f842e319de
commit
039824c0ee
2 changed files with 9 additions and 28 deletions
|
@ -106,10 +106,6 @@ const useMapWithStyle = ({
|
|||
});
|
||||
setGeolocate(geolocate);
|
||||
map.addControl(geolocate);
|
||||
geolocate.on("error", onGeolocateError);
|
||||
return () => {
|
||||
geolocate.off("error", onGeolocateError);
|
||||
};
|
||||
}
|
||||
if (!allowGeolocate && geolocate) {
|
||||
map.removeControl(geolocate);
|
||||
|
@ -117,6 +113,15 @@ const useMapWithStyle = ({
|
|||
}
|
||||
}, [map, geolocate, allowGeolocate]);
|
||||
|
||||
useEffect(() => {
|
||||
if (geolocate) {
|
||||
geolocate.on("error", onGeolocateError);
|
||||
return () => {
|
||||
geolocate.off("error", onGeolocateError);
|
||||
};
|
||||
}
|
||||
}, [geolocate]);
|
||||
|
||||
return {
|
||||
map,
|
||||
bodyId,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue