Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

318
Visualizações
Problem with using method setPaths ( Leaflet PolylineDecorator)

I wanna update the component and change the lines.

When I try to send new props with coordinates, old coordinates also staying.

const PolylineDecorator = withLeaflet(props => {

const { positions } = props;
const polyRef = useRef();

useEffect(() => {
const polyline = polyRef.current.leafletElement; //get native Leaflet polyline
const { map } = polyRef.current.props.leaflet; //get native Leaflet map

L.polylineDecorator(polyline, {
 patterns: props.patterns,
}).addTo(map);
}, []);
return <Polyline ref={polyRef} {...props} opacity="0" />;
});

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It is tricky to debug this one out without trying in the local machine. But It looks like you need to pass positions to the useEffect as follows, so it will re-render every time positions are changing.

useEffect(() => {
 const polyline = polyRef.current.leafletElement; //get native Leaflet 
 polyline
 const { map } = polyRef.current.props.leaflet; //get native Leaflet map

 L.polylineDecorator(polyline, {
 patterns: props.patterns,
 }).addTo(map);
}, [positions]);
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda