-
Notifications
You must be signed in to change notification settings - Fork 889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changing/updating properties of components is prohibitively difficult #94
Comments
Hi, I'm not sure I understand the problem here, is it with React's diffing or applying the properties? The dummy |
Interesting tip on changing the I think you do understand the problem, based on your suggestion -- updating attributes of a I'm short on time now but can try to boil this down to a working repro if that is useful. |
The GeoJson The path options should be updated though, here is the logic handling this: https://github.com/PaulLeCam/react-leaflet/blob/master/src/Path.js#L32 |
Heres a naive implementation of an updatable |
@luqmaan that's essentially what I ended up doing, though I did not encapsulate it into a component like you did. @PaulLeCam I'm under the gun right now and can't put together a repro just yet. Will do so as soon as I'm able. |
@luqmaan I wonder what is the advantage of this solution rather than changing the I haven't done any test, I just assumed having React remove the node and Leaflet create a new one would be less expensive than having Leaflet remove its layers, add new ones, and apply the styles, but maybe I'm wrong. |
@PaulLeCam that's the technique @mourner recommends, in absence of any formal way to update data: Leaflet/Leaflet#1416 (comment) |
@ericsoco Thanks for the link, I'll add this to the next release to handle dynamic changes of the data without needing to change the I haven't had time to investigate your issue yet, but I set a JSFiddle up, if you could please use it to try to reproduce the issue when you have some time that would help! |
Thanks @PaulLeCam -- still working toward a deadline (two projects converging...) so will be a bit but will come back to this as soon as I'm able! |
Also related to changing classnames is Leaflet/Leaflet#2662 |
Thanks for this link. |
I ran into this exact issue, thanks @PaulLeCam for the suggestion about updating the key. That was more difficult to debug than it should have been. |
I ran into a situation using
GeoJson
in which I wanted to highlight a selected GeoJson layer on click, and was trying to do so by adding/removing a class. However, I wasn't able to make the changes happen in React'srender
cycle, and instead had to manually select elements (withdocument.querySelector
) and add/remove classes.I believe this is due to the way Leaflet manipulates the DOM on its own, and how
react-leaflet
produces dummy<div>
s for React. I was conditionally settingclassName
s, but React's DOM diff was looking at those<div>
s instead of of the<path>
s to whichreact-leaflet
was applying the actual classes.This resulted in no change:
Instead, I had to add an additional
className
that containsthing.properties.id
and use that to form a selector to remove'selected-foo'
from the previously-selected element, when a new element is selected.I'm not sure how
react-leaflet
might solve this problem -- perhaps theclassName
s can be applied to the dummy<div>
s as well as the rendered<path>
elements, and the React DOM diff will pick up the changes? Not sure if the changes would propagate through to the<path>
elements though, seems like that would still be up toreact-leaflet
/ Leaflet...I also don't know if this is something that needs to be solved for arbitrary attributes, or just for
className
/class
. Haven't thought about it that deeply.The text was updated successfully, but these errors were encountered: