react-leaflet icon indicating copy to clipboard operation
react-leaflet copied to clipboard

TileLayer component doesn't re-render elements on className prop change

Open mattgbrich opened this issue 8 years ago • 3 comments

Bug report in v1

Not sure if this is a legitimate bug, or a limitation with the way Leaflet renders elements in the DOM

Expected behavior

When the className prop updates, the component re-renders elements with values from new prop

Actual behavior

When the className prop updates, the new class does not get applied to the element in the DOM

Steps to reproduce

Here's an example:

https://codepen.io/metropolis_4/pen/bjqJNB

Click on the marker, and then click the button in the popup. Clicking this toggles the state tileLayerClass from "" to "grayscale"

mattgbrich avatar Jul 23 '18 14:07 mattgbrich

This might be my bad for mis-reading the docs. I noticed the line that says

ℹ️ All other properties are passed as parameters and dynamic, they will cause the layer to redraw if they change.

I thought it was applying to all Raster Layers, but looks like maybe it only applies to WMSTileLayer?

mattgbrich avatar Jul 23 '18 14:07 mattgbrich

Yes this notice is about WMSTileLayer, not the other raster layers. Only the properties documented as dynamic are expected to get updated. In your case you'll probably want to change the element's key in order to re-render it as needed.

PaulLeCam avatar Jul 23 '18 14:07 PaulLeCam

That makes sense, thanks for the clarification!

mattgbrich avatar Jul 24 '18 15:07 mattgbrich