Open SalahAdDin opened 2 years ago
The function fires many times because you should use map.on inside useEffect, as it behaves like addEventlistener.
So something like:
const onShowLocation = (result: LeafletEvent) => {
if (result) {
// read location here
}
};
useEffect(() => {
map.addControl(searchControl);
map.on('geosearch/showlocation', onShowLocation);
return () => {
map.removeControl(searchControl);
map.off('geosearch/showlocation', onShowLocation);
};
}, []);
...```
Thanks for this greap library, we could replace
react-leaflet-search
with this library.Something is missing: we want to get the location from the selected result.
Right now we do it by a fired event(
geosearch/showlocation
) as follows:The problem with this approaching is the event is fired many times, and it can affect the render performance:
The aforementioned library uses a callback(
onChange
) to handle it.What's about using a kind of function to get it?
Thank you