Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

118
Vistas
React Leaflet layer marker doesn't disapperar even after state is empty

My state looks like:

this.state = {
    onWayMarkers: [],
    preparingMarkers: [],
    concludedMarkers: [],
    cancelledMarkers: [],
}

May React Leaflet inside a <MapContainer>:

    <TileLayer
        attribution='&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
        url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
    />        
    <LayersControl>
        <LayersControl.Overlay checked name="Concluded">
            <LayerGroup>
                {this.state.concludedMarkers.map((element, idx) => {
                    const icon = L.divIcon({
                       className: 'custom-icon',
                           html: ReactDOMServer.renderToString(this.mapIconConcluded(element.label)),
                            iconSize: [30, 30],
                            iconAnchor: [10, 32]
                        });

                    return(
                        <Marker key={`marker-${idx}`} position={element.coord} icon={icon}>
                        <Popup>
                        <span>{element.order_id}</span>
                        </Popup>
                        </Marker>
                    );
                })}
            </LayerGroup>
        </LayersControl.Overlay>

I have one of this piece of layer codes for each array item in this.state:

<LayersControl.Overlay name="name"><LayerGroup>{array.map}</LayerGroup></LayersControl.Overlay>  

When I update the state and clear one of the arrays, this happens:
The marker from the specific array disappears
But when I deactivate and activate the layer, the marker comes back ... without the Popup. I've printed console.log(this.state.array) and even with the array emptied the marker comes back

Any ideia on why this is happening and how can I fix it?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda