React-map-gl: _this.mapRef.getMap is not a function

Created on 18 Aug 2019  路  2Comments  路  Source: visgl/react-map-gl

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?

Most helpful comment

Needed to call current on mapRef before getMap

const map = this.mapRef.current.getMap()

All 2 comments

Needed to call current on mapRef before getMap

const map = this.mapRef.current.getMap()

Needed to call current on mapRef before getMap

const map = this.mapRef.current.getMap()

kindly update the docs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bogdancaspar picture bogdancaspar  路  3Comments

miccferr picture miccferr  路  4Comments

Majaspic picture Majaspic  路  4Comments

nip10 picture nip10  路  4Comments

ckalas picture ckalas  路  5Comments