I am developing a React app on my Ubuntu 20.4 VM machine in a chrome Version 100.0.4896.127 (Official Build) (64-bit) browser.
I have created the following app:
https://codesandbox.io/s/react-leaflet-map-with-marker-forked-vtq00e?file=/Map.js
I am trying to set a marker when clicking on the map using the following:
In my Map.js I set the click event:
return (
<div id="map" style={style}>
<MapContainer
// center={[40.0151, -105.2921]}
center={[40.7579747, -73.9877313]}
// @ts-ignore
onClick={addMarker}
zoom={15}
style={{ height: "90%" }}
// @ts-ignore
onZoomEnd={console.log}
>
The following function should then set the marker:
function addMarker(e) {
console.log("marker \n");
const { markers } = this.state;
markers.pop();
markers.push(e.latlng);
this.setState({ markers });
}
However, when I click on the map nothing is happening. I also do not get a console output.
Any suggestions what I am doing wrong?
I appreciate your replies!