0

I'm trying to use Mapbox Geocoder without map in React (see https://docs.mapbox.com/mapbox-gl-js/example/mapbox-gl-geocoder-no-map/ ). I can successfully create a refs but once I use it as an argument in .addTo() function, I get this error message although the refs is an [object HTMLDivElement]:

Error: addTo Container must be a mapbox-gl-js map or a html element reference 

The code is here: https://codesandbox.io/s/patient-hill-xvh12?fontsize=14&hidenavigation=1&theme=dark

1 Answer 1

1

See https://github.com/mapbox/mapbox-gl-geocoder/blob/master/API.md#addto you must pass a string selector like #id or .class to addTo, not a reference to the actual element.

Sign up to request clarification or add additional context in comments.

1 Comment

String refs are deprecated in React (reactjs.org/docs/refs-and-the-dom.html#legacy-api-string-refs) so is there another way around?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.