I am using react-map-gl
for a project. The map itself renders but i can’t use useMap()
. It always logs { current: undefined }
. Has anyone a solution?
My layout.tsx
contains:
import { MapProvider } from "react-map-gl";
....
<div className="flex h-screen">
<MapProvider>
<div>
{children}
</div>
<InternalMap />
</MapProvider>
</div>
);
InternalMap.tsx
looks like:
import MapGL, { ScaleControl } from "react-map-gl";
<MapGL
....
>
....some more stuff
The children page looks like:
import { useMap } from "react-map-gl";
const { default: map } = useMap();
console.log(map, useMap())
2
Answers
I messed up some imports in my monorepo and tried to imported
react-map-gl
from a wrong place with a version missmatchyou have to use
An API access token is required to use Mapbox GL.
CodeSandbox URL:
https://codesandbox.io/p/sandbox/react-mapbox-gl-turf-mueyi?file=%2Fsrc%2Findex.js%3A1%2C1-65%2C1