Skip to content
Discussion options

You must be logged in to vote

I struggled with this recently. This is what I have done:

From outside, I made the ref for the map

  const mapRef = createRef<MapRef>();

  const mapContextValue: MapContextProps = {
    map: mapRef,
    container: null,
    isDragging: false,
    eventManager: undefined,
  };

  return (
    <MapContext.Provider value={mapContextValue}>
      ...
      <MapViewComponent />
      ...
    <MapContext.Provider>
   ...

Then in MapViewComponent I use forwardRef to put it into the ReactMapGL

<ReactMapGL ref={forwardedRef} ...>
   ...
</ReactMapGL>

So far the typescript stops complaining, but I DON'T KNOW is that correct way or not. I can't believe I can't find an example about this on github a…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by martpet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants