#Can't use marker inside a MapView component.

4 messages · Page 1 of 1 (latest)

high breach
#
        initialViewState={{
          latitude: 17.2,
          longitude: 72.4,
          zoom: 10,
        }}>
        <Marker latitude={17.2} longitude={72.4} />
      </MapView>```
when i try to do this, i get this 
```Cannot destructure property 'map' of '(0 , import_react4.useContext)(...)' as it is null.
    at Marker (marker.ts:40:10)```

when i checked into the code of Marker, i found

```const {map, mapLib} = useContext(MapContext);```
so, it is expecting a mapContext which happens to be null.

i faced no problems, when i used it with original Map component of react-map-gl

i checked into MapView component

``` return transformRequest ? (
      <ReactMapGL
        {...props}
        mapLib={mapLib ?? maplibregl}
        mapStyle={mapStyle ?? geoConfig.maps?.default}
        ref={ref}
        style={styleProps}
        transformRequest={transformRequest}
        fog={props.fog}
        terrain={props.terrain}
      />
    ) : null;

the issue probably is that transForm request being async hasn't completed when marker tries to get the mapcontext, so MapView is returning null when the Marker component tries to access context. I can't figure out how to get around that. how can i check the status of MapView.

midnight kettle
#

Hello, @high breach and welcome to Amplify! Are you using any type of useState hook by chance to manage the state of when the map is loading? Would you mind sharing the full file/code of how you're handling the maps?

high breach
high breach