From 039824c0ee01ae265523859db0bb4b2d3f6bb4e7 Mon Sep 17 00:00:00 2001 From: Johannes Marbach Date: Fri, 10 Feb 2023 08:25:59 +0100 Subject: [PATCH] Move error handling to separate effect --- src/components/views/location/Map.tsx | 13 ++++++---- .../PictureInPictureDragger-test.tsx.snap | 24 ------------------- 2 files changed, 9 insertions(+), 28 deletions(-) diff --git a/src/components/views/location/Map.tsx b/src/components/views/location/Map.tsx index c1dbcab337..22a4bda63e 100644 --- a/src/components/views/location/Map.tsx +++ b/src/components/views/location/Map.tsx @@ -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, diff --git a/test/components/structures/__snapshots__/PictureInPictureDragger-test.tsx.snap b/test/components/structures/__snapshots__/PictureInPictureDragger-test.tsx.snap index 0e382ea7f0..4f95f5e41f 100644 --- a/test/components/structures/__snapshots__/PictureInPictureDragger-test.tsx.snap +++ b/test/components/structures/__snapshots__/PictureInPictureDragger-test.tsx.snap @@ -30,27 +30,3 @@ exports[`PictureInPictureDragger when rendering the dragger with PiP content 1 a `; - -exports[`PictureInPictureDragger when rendering the dragger with PiP content 1 and rerendering PiP content 1 should not change the PiP content: pip-content-1 1`] = ` -
- -
-`; - -exports[`PictureInPictureDragger when rendering the dragger with PiP content 1 should render the PiP content: pip-content-1 1`] = ` -
- -
-`;