Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On result handler #9

Closed
sos0 opened this issue Nov 10, 2018 · 9 comments
Closed

On result handler #9

sos0 opened this issue Nov 10, 2018 · 9 comments

Comments

@sos0
Copy link

sos0 commented Nov 10, 2018

Hello,

Separate question from my other one (#8), how do I add a onResults or onResult handler to the component?

@SamSamskies
Copy link
Owner

There's not an easy way to do this right now. I'll try and work on adding the ability to pass these in as props this weekend.

@sos0
Copy link
Author

sos0 commented Nov 10, 2018

Thanks so much!

@SamSamskies
Copy link
Owner

I added props for onResults and onResult in the latest version. README is updated with all available props. Let me know if you have any problems.

@sos0
Copy link
Author

sos0 commented Nov 13, 2018

Am I correct in understanding that all I have to do is pass a function to the onResult prop to achieve the same result as this example?

I tried this and nothing got printed after searching + selecting a result:

_onGeocoderResult = (results) => {
  console.log(results);
}
// ... a bunch of code and ReactMapGL wrapper 
<Geocoder mapRef={this.mapRef}
  onResult={this._onGeocoderResult}
  onViewportChange={this._handleGeocoderViewportChange}
  mapboxApiAccessToken={config.MAPBOX_PUBLIC_TOKEN} />

Again, thanks so much for your help!

@SamSamskies
Copy link
Owner

That should work. Could you verify that you're using v1.4.5?

See example here: https://codesandbox.io/s/0vpoxn0n9l

I just noticed there's an existing bug with mapbox-gl-geocoder that causes onResult to fire twice. mapbox/mapbox-gl-geocoder#99.

@sos0
Copy link
Author

sos0 commented Nov 13, 2018

I'll try removing my dependencies and re-updating!

@SamSamskies
Copy link
Owner

Does the example work for you? If it doesn't, let me know what your search query is.

@sos0
Copy link
Author

sos0 commented Nov 13, 2018

It worked! I just had to remove my node_modules folder and reinstall. :) Thanks so much Sam!

@SamSamskies
Copy link
Owner

No problem. Let me know if that bug causing the event to fire twice is a problem for you. I can try and help them fix the bug or figure out a workaround if it is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants