PaulLeCam / react-leaflet

React components for Leaflet maps
https://react-leaflet.js.org
Other
5.19k stars 887 forks source link

Update `interactive` prop #1064

Closed IanMayo closed 1 year ago

IanMayo commented 1 year ago

The underlying leaflet marker object should be updated if interactive changes in the props.

PaulLeCam commented 1 year ago

Hi, thanks for your PR but I can't find any mention of the setInteractive method in Leaflet's docs, could you please point me to the relevant page?

IanMayo commented 1 year ago

Hello @PaulLeCam

I'm afraid I don't have easy access to the leaflet sources - but was following the code pattern in the rest of this method. It was an attempt to update this property: image

PaulLeCam commented 1 year ago

Yes that can be set as an option, but I'm wondering about the method call you're using here? I don't want to use any undocumented or internal Leaflet API in React Leaflet to avoid possible breaking changes.

IanMayo commented 1 year ago

Aah, I see my mistake.

Is there alternate way we would update the state of interactive?

PaulLeCam commented 1 year ago

Yes, if you set a unique key on the element you want to change props for, React will re-create it so the options should be picked-up by React Leaflet when creating the new element.

IanMayo commented 1 year ago

Thanks for your support @PaulLeCam

Behold my current workaround: image

It looks like my workaround is actually the valid solution, though it looks more like a react-trick than formal support for the property. But, if you do feel this is the valid solution, please feel free to close the PR.

Thanks again :-) Ian