Last active
July 6, 2021 23:37
-
-
Save sadewole/b8f271af26092932797bf1f9adb0df1c to your computer and use it in GitHub Desktop.
Load map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const map = useRef(null); | |
const mapContainerRef = useRef(null); | |
mapboxgl.accessToken = process.env.REACT_APP_MAPBOX_API; // your mapbox api | |
useEffect(() => { | |
if (map.current) return; // Checks if there's an already existing map initialised. | |
map.current = new mapboxgl.Map({ | |
container: mapContainerRef.current, | |
style: 'mapbox://styles/mapbox/streets-v11', | |
zoom: 9, | |
center: [3.361881, 6.672557], | |
}); | |
// clean up on unmount | |
return () => map.current.remove(); | |
}, []) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment