When I am trying to render react-leaflet-search, I get an error. When I am trying to use the solution for that error, react is compiling but component does not seem to be rendering.
I tried their example simple search. Getting the same error
TypeError: Cannot read property 'map' of undefined
new ReactLeafletSearch
C:/Users/project/node_modules/react-leaflet-search/lib/React-Leaflet-Search.js:106
103 | });
104 | _this.SearchInfo = null; // searched lat,lng or response from provider
105 |
> 106 | _this.map = context.map || props.leaflet.map;
| ^ 107 | return _this;
108 | }
109 |
I tried this solution (from the react-leaflet-search page)
const searchComponent = props => (<ReactLeafletSearch position="topleft" />);
i even tried this:
const searchComponent = withLeaflet(ReactLeafletSearch);
these lines bypass the "error" but no component seems to be rendering.
my react-leaflet Map component is loading, the zoom +/- buttons too, but not the search.
this is the code that i am using map example ofcourse i am also doing:
import { ReactLeafletSearch } from "react-leaflet-search";
the only difference is that after line 31 i add my component.
31. </Marker>
32. <searchComponent></searchComponent>
33. </Map>
and nothing seems to be rendering at all.
The result I would expect is a search component like the one showing in this working example
To reproduce this example you need to:
Install
leaflet
,react-leaflet
,react-leaflet-search
.After, you need to install
babel-polyfill
and if you use react-leaflet v2 you should wrap this component with thewithLeaflet
method. It is also documented as a github issue.In the render method of example's SimpleExample component:
Don't forget also to add the
map height
and to importleaflet.css
Demo