CodePudding user response:
Okay, I found the problem. Look's like I have to clear markers from clusterer during every rerender. Updated hook code:
let markerClusterer: MarkerClusterer | null = null;
let markers: google.maps.Marker[] = [];
useEffect(() => {
markerClusterer?.clearMarkers();
markers.forEach((marker) => marker.setMap(null));
const markers = addresses.map((address) => {
new window.google.maps.Marker({
position: {
lat: address.attributes.lat,
lng: address.attributes.lng,
},
map: map,
});
});
new MarkerClusterer({ map, markers });
}, [addresses, map, mapParams]);
Thank Piero Alberto for the clue in his question