I'm building a small App using ReactJS and Mapbox GL JS.
const MapRender = () => {
const mapContainerRef = useRef(null);
const map = new mapboxgl.Map({
container: mapContainerRef.current,
style: "mapbox://styles/mapbox/streets-v11",
center: [0, 0],
zoom: 1
});
map();
useEffect(()=>{
..........//Code
},[]);
return (
<div>
<div className="map-container" ref={mapContainerRef} />
</div>
);
};
export default MapRender;
My code above basiclly display a map on a webpage. But I got the error messenge:
Invalid type: 'container' must be a String or HTMLElement.
Everythings will be fine if I put const map = new mapboxgl.Map() into useEffect() but it's mean eachtime when I setState the Map will call and reload again.
I expect the use the same map during the whole runtime of my app.
How can I do that ?
