Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

312
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!