I can't understand how to update my markers correctly using react-leaflet. Using this example:
import React from 'react';
import { render } from 'react-dom';
import { connect } from 'react-redux';
import { Map, Marker, TileLayer } from 'react-leaflet';
const map = props => (
<Map center={[51.505, -0.09]} zoom={13}>
<TileLayer
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
attribution='© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
/>
{props.markers.map(m => (
<Marker position={m.position} />
))}
</Map>
);
const mapStateToProps = state => ({
markers: state.markers // array of objects with positions. this can change
});
render(connect(mapStateToProps)(map), document.getElementById('map-container'));
This works, but I don't know if it's the correct way of doing it. Because in that case when the markers update their position (or there are more markers), Leaflet will remove the markers and put new ones, instead of updating the position of the original markers.
So my question is that. Am I doing it right or this is not the most performant way?
Thanks!