I'm trying to use Leaflet in my React App. I'm running into an issue. Leaflet.js requires the div component to pre-exist when initiating the map. React doesn't "create" the div until it renders the component, so leaflet is throwing an error. Both getDOMNode() and findDOMNode() return "not a function" for whatever reason.
Code:
import React from 'react';
import {render} from 'react-dom';
import L from 'leaflet';
...a little later
export default class Mapbox extends React.Component {
render() {
var map = L.map('map').setView([51.505, -0.09], 13);
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
return (
<div id="map">
<h1>hi</h1>
</div>
);
This returns an error that "Map Container not Found".
Thanks.