Skip to content

Commit

Permalink
fix(Polyline): fix component uninstall issue. (#326)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Aug 22, 2023
1 parent b829e56 commit f465936
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions packages/polyline/src/usePolyline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ export function usePolyline(props = {} as UsePolyline) {
const { map } = useMapContext();
useEffect(() => {
if (map && !polyline) {
let instance: AMap.Polyline = new AMap.Polyline(other);
const instance: AMap.Polyline = new AMap.Polyline(other);
map.add(instance);
setPolyline(instance);
return () => {
if (instance) {
if (AMap.v) {
map && map.remove(instance);
} else {
// 暂不使用这个 API,这个不兼容 v1.4.xx,改用 map.remove API
map && map.removeLayer(instance);
}
setPolyline(undefined);
}
};
}
}, [map]);
return () => {
if (polyline) {
if (AMap.v) {
map && map.remove(polyline);
} else {
// 暂不使用这个 API,这个不兼容 v1.4.xx,改用 map.remove API
map && map.removeLayer(polyline);
}
setPolyline(undefined);
}
};
}, [map, polyline]);

useEffect(() => {
if (polyline) {
Expand Down

0 comments on commit f465936

Please sign in to comment.