Using 5.0.10
I'm trying to access to MapBox api using getMap() as described in the doc.
But I keep getting the same error:
Uncaught TypeError: _this.mapRef.getMap is not a function
My code looks like this:
import React, { Component } from 'react';
import ReactMapGL from 'react-map-gl';
class Map extends Component {
mapRef = React.createRef();
componentDidMount() {
console.log(this.mapRef); // => log includes getMap() function
const map = this.mapRef.getMap() // => TypeError!!
}
render() {
return (
<ReactMapGL ref={this.mapRef} />
)
}
}
Am I missing something or is it broken?
Needed to call current on mapRef before getMap
const map = this.mapRef.current.getMap()
Needed to call
currentonmapRefbeforegetMapconst map = this.mapRef.current.getMap()
kindly update the docs.
Most helpful comment
Needed to call
currentonmapRefbeforegetMap