florian
florian

Reputation: 1001

How to use MapboxGeocoder with no map in React

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

Upvotes: 0

Views: 1187

Answers (1)

AndrewHarvey
AndrewHarvey

Reputation: 3055

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.

Upvotes: 1

Related Questions