const ZoomToLocation = ({latitude, longitude}) => {
const map = useMapEvents({
click() {
map.setView([latitude, longitude], 15)
}
})
return null
}
function MyMap() {
return(
<MapContainer>
{loc.map(loc => (
<Marker
key={loc.properties.id}
position={[loc.properties.y, loc.properties.x]}>
<ZoomToLocation latitude={loc.properties.y} longitude={loc.properties.x}/>
</Marker>
))
}
</MapContainer>
)}
It maps everything in the <Marker>
component as I would expect, but doesn't do it in <ZoomToLocation>
. Instead, it just returns the last item in the JSON.
Any idea what I'm doing wrong?