How to use it with CRA? #1382
Unanswered
DavideVito
asked this question in
Q&A
Replies: 1 comment
-
I'm not on the team or anything, but I was looking for help with something else here (getting frustrated with that lol) and noticed that nobody answered you yet. Here's the map component from my own CRA app, which I finally got working today. I started by copying a repo I found on github, and also got help from reactiflux (discord) or I would never in a million years have figured out how to use this in CRA. import React, { useState } from 'react'
import { isMobile } from 'react-device-detect'
import ReactMapGL from 'react-map-gl'
const MapView = ({ lat, lng }) => {
const [viewport, setViewport] = useState({
latitude: 45,
longitude: 73,
zoom: 7,
})
const mapStyle = {
width: '100%',
height: 350,
}
return (
<div>
{!isNaN(lat) ? (
<ReactMapGL
eventRecognizerOptions={eventRecognizerOptions}
mapboxApiAccessToken={process.env.REACT_APP_MAPBOX_ACCESS_TOKEN}
mapStyle="mapbox://styles/mapbox/streets-v11"
{...mapStyle}
{...viewport}
onViewportChange={(viewport, mapStyle) => {
setViewport({ ...viewport, latitude: lat, longitude: lng })
}}
/>
) : (
<div>Loading...</div>
)}
</div>
)
}
export default MapView |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I've tried to import your Control Example into a brand new Create React App application, but the map doesn't render into the dom, how can I solve?
Here is my code, can u please help me solving the problem?
Beta Was this translation helpful? Give feedback.
All reactions