Using “react-leaflet”: “^2.6.0” it does not call onEachFeature every time GeoJSON data is changed. Even if GeoJSON is properly changed and displayed on map I got old values in onEachFeature. Is there any workaround here?
import React from "react";
import { GeoJSON } from "react-leaflet";
class GeoJsonArea extends React.Component {
constructor(props) {
super(props);
this.state = {
};
this.onEachFeature=
this.onEachFeature.bind(this);
}
componentDidUpdate(prevProps) {
if (
(
this.props.geoJsonData &&
this.props.geoJsonData!== prevProps.geoJsonData)
) {
this.props.geoJsonRef.current.leafletElement.clearLayers();
this.props.geoJsonRef.current.leafletElement.addData(
this.props.geoJsonData
);
}
}
// keep getting old values from first render
onEachFeature= (feature, layer) => {
console.log(feature)
};
render() {
return (
<GeoJSON
ref={this.props.geoJsonRef}
onEachFeature={this.onEachFeature}
/>
);
}
}
export default GeoJsonArea ;