react-leaflet-div-icon
react-leaflet-div-icon copied to clipboard
Fixed issue with redundant mounting/unmounting + better position check
Hey,
Since the ContextProvider component was created in the renderComponent function, it caused react to mount and unmount the component on every render, since renderComponent created a new ContextProvider class every time. We had a marker with an image in it, and we could see the image reload on every render. If you put a componentDidMount in your inner component you can see it being raised on every render. We have moved the creating of the ContextProvider to the componentDidMount, as there is no real reason to create it every time, specifically since context is added statically and doesn't change in runtime.
We also we have changed the comparison of the position, since if you use the component like:
<DivIcon position={[this.props.lat, this.props.lng]}
It will cause the setLatLng function to be called even if nothing changed, since the comparison was done by array reference.