SamSamskies / react-map-gl-geocoder

React wrapper for mapbox-gl-geocoder for use with react-map-gl
MIT License
123 stars 29 forks source link

Can't find a way to trigger the first result for onResults #91

Closed TMinh25 closed 3 years ago

TMinh25 commented 3 years ago

Can you give me an example for onResults props?

SamSamskies commented 3 years ago

Hi @TMinh25, I'm not sure what you're trying to do, so I just made a simple example that console logs the results. https://codesandbox.io/s/react-map-gl-geocoder-v2-onresults-example-96nve

SamSamskies commented 3 years ago

I just read the title of the issue and figured out what you're trying to do. haha. I haven't done this before, but I think you can execute the query function on the Mapbox geocoder object. https://github.com/mapbox/mapbox-gl-geocoder/blob/master/API.md#query

SamSamskies commented 3 years ago

I played around with it a bit and there actually doesn't seem to be a good way to do it because results are queried as you type, so onResults gets called many times and it ends up selecting a result before you finish typing your query.