Cannot use useMap to get updated viewport from Map #1766
-
Hello guys! Today I was updating the code to use react-map-gl v7 and I came up with an issue. Before updating to v7, I could use MapContext with useContext in order the current zoom of a map. So I could do something like this:
That way that component would have always the updated zoom level of the map on that context. However, now I cannot use MapContext as it was removed and using useMap is not getting the current values of the different maps as it is only updated when a new map is mounted or unmounted on the MapProvider. Just to clarify, I thought I could do the following in order to get the currentZoomLevel at every moment but using useMap:
But this is just getting the initial value when the map in mounted not the updated value. So the soluion I implemented was creating a currentZoomLevel state variable on a father component, and pass the setCurrentZoomLevel function to the react-map-gl map in order to update the currentZoomLevel when the move event is triggered. Am I missing something? Otherwise, do you think it would be interesting to implement this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
https://github.com/visgl/react-map-gl/tree/master/examples/get-started/hook |
Beta Was this translation helpful? Give feedback.
https://github.com/visgl/react-map-gl/tree/master/examples/get-started/hook