'How to access MapboxGL methods inside react native functional component?
I am working on a react native project and I am using MapboxGL. The problem is I can't access any of the methods of MapboxGL.
const Home = () => {
.... some code ...
<MapboxGL.MapView
ref={c => (this._map = c)}
style={styles.map}
onRegionIsChanging={onRegionIsChanging}
onRegionDidChange={onRegionDidChange}
surfaceView>
{/* Display user location */}
{/* Checks if the user has granted location permission to the app. */}
{locationPermissionGranted && (
<>
<MapboxGL.UserLocation visible onUpdate={userLocationUpdate} />
</>
)}
<MapboxGL.Camera
followZoomLevel={15}
zoomLevel={15}
followUserLocation={followUserLocation}
centerCoordinate={centerCoordinate}
/>
</MapboxGL.MapView>
}
This is my code and since I am using functional component I am not able to use this keyword. I have also tried changing to class component but still the methods of MapboxGL return undefind or something like "moveTo is not function" (when I am trying to access moveTo method,for instance.)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
