Answer the question
In order to leave comments, you need to log in
Why does Popup open three times in one click?
console.log is called three times when I click the Marker and four more times when I close the popup. Can anyone explain why this is happening?
const LocationMarker = ({elem, setIsVpnChanged, isVpnChanged, handleVpnStatus}) => {
const map=useMapEvents({
popupopen(){
// setIsVpnChanged((prev)=>({...prev, isChanged:true}))
console.log('is opened')
},
popupclose(){
setIsVpnChanged((prev)=>({...prev, isChanged:false}))
console.log('is closed')
}
})
return <Marker position={elem.position} className="marker__down" opacity={(elem.health?1:0.5)} >
<Popup>
...Some html...
</Popup>
</Marker>
}
<MapContainer center={vpns[0].position && [0, 0]} zoom={2} id="map" className='map'>
<TileLayer
attribution='© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
/>
{vpns.map((elem) =>
<LocationMarker elem={elem} setIsVpnChanged={setIsVpnChanged} isVpnChanged={isVpnChanged} handleVpnStatus={handleVpnStatus} key={uuidv4()}/>
)}
</MapContainer>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question