Skip to content

Commit 4c482bc

Browse files
committed
Fix issue with visible prop
1 parent 3bf1454 commit 4c482bc

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

Diff for: src/components/CustomOverlay.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ function createPopupClass() {
1313

1414
Popup.prototype = Object.create(google.maps.OverlayView.prototype);
1515

16+
Popup.prototype.show = function () {
17+
this.containerDiv.style.visibility = 'visible';
18+
};
19+
20+
Popup.prototype.hide = function () {
21+
this.containerDiv.style.visibility = 'hidden';
22+
};
23+
1624
Popup.prototype.onAdd = function () {
1725
this.getPanes().floatPane.appendChild(this.containerDiv);
1826
};
@@ -52,18 +60,28 @@ const CustomPopup = ({
5260
passThroughMouseEvents
5361
}) => {
5462
const containerEl = useRef(null);
63+
const popoverRef = useRef(null);
64+
5565
useEffect(() => {
5666
if (map) {
5767
const pos = new google.maps.LatLng(position.lat, position.lng);
5868
const Popup = createPopupClass();
59-
new Popup({
69+
popoverRef.current = new Popup({
6070
position: pos,
6171
content: containerEl.current,
6272
map,
6373
passThroughMouseEvents
6474
});
6575
}
6676
}, [map]);
77+
78+
useEffect(() => {
79+
const popover = popoverRef.current;
80+
if (popover) {
81+
visible ? popover.show() : popover.hide();
82+
}
83+
}, [visible]);
84+
6785
return (
6886
<div
6987
className={className}

0 commit comments

Comments
 (0)