I'm trying to load the leaflet map but it is giving me an error:
Attempted import error: 'Map' is not exported from 'react-leaflet' (imported as 'LeafletMap').
I tried to install react-leaflet again and also tried to import leaflet/dist/leaflet.css in my App.js file but it is still showing me the error. Here is the code
Map.js
import { Map as LeafletMap, TileLayer } from "react-leaflet";
import "./Map.css";
function Maps({ center, zoom }) {
return (
<div className="map">
<LeafletMap center={center} zoom={zoom}>
<TileLayer
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
attribution='© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
/>
</LeafletMap>
</div>
);
}
export default Maps;
App.js
import './App.css'
import Maps from './Maps'
import 'leaflet/dist/leaflet.css'
function App() {
const [mapCenter, setMapCenter] = useState({ lat: 34.80746, lng: -40.4796})
const [mapZoom, setMapZoom] = useState(3)
return (
<div className="app">
<Maps
center= {mapCenter}
zoom= {mapZoom}
/>
</div>
)
}
export default App;