Hi I used the code example in mapbox but it shows nothing (width=0) please guide me, how to implement a map in react js. here is my index.js file:
mapboxgl.accessToken =
"My token";
class Application extends React.Component {
constructor(props) {
super(props);
this.state = {
lng: 5,
lat: 34,
zoom: 2
};
}
componentDidMount() {
const map = new mapboxgl.Map({
container: this.mapContainer,
style: "mapbox://styles/mapbox/streets-v11",
center: [this.state.lng, this.state.lat],
zoom: this.state.zoom
});
map.on("move", () => {
this.setState({
lng: map.getCenter().lng.toFixed(4),
lat: map.getCenter().lat.toFixed(4),
zoom: map.getZoom().toFixed(2)
});
});
}