-
Notifications
You must be signed in to change notification settings - Fork 880
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
react-leaflet Components cannot be wrapped in React components #73
Comments
Since The wrapping component can pass |
@uniphil i'm running into this same problem, and if you closed this ticket because you found a solution, it is unclear to me what it was. can you elaborate? |
Here is an example of how to create custom components, and the documentation. TLDR; Notice line 5. When creating a custom component, the The initial example can be fixed by adding these props to the import React, { Component } from 'react';
import { Map, Marker } from 'react-leaflet';
class WrappedMarker extends Component {
render() {
const { map, layerContainer } = this.props; //Given by the `Map` component
return (
<Marker
map={map} /* pass down to Marker */
layerContainer={layerContainer} /* pass down to Marker */
position={[51.505, -0.09]}
/>
);
}
}
export default class MapView extends Component {
render() {
return (
<Map center={[51.505, -0.09]} zoom={13}>
<WrappedMarker />
</Map>
);
}
} |
thank you, @jgimbel. that cleared things up. makes much more sense. |
in react-leaflet 1.1.1version, the map and layerContainer is not in props of child component |
Attempted import error: 'Map' is not exported from 'react-leaflet' (imported as 'LeafletMap'). |
I changed 'Map' to 'MapContainer' in the import: import { MapContainer as LeaftletMap, TileLayer } from 'react-leaflet'; |
thanks it works for me |
Attempted import error: 'MapContainer' is not exported from 'react-leaflet'....getting this error |
which version do you use? |
Use 'MapContainer' instead of 'Map' |
After changed from 'Map' to 'MapContainer' in the import I got this error C:/Users/Private/node_modules/@react-leaflet/core/esm/index.js
|
I had a similar issue and came up with this solution https://codesandbox.io/s/react-leaflet-overlay-import-wu6ct?file=/src/index.js:333-704 |
Having the same issue after updating map to mapcontainer |
In apps I work on, we often want to do things like:
Marker
wrapper code between different views.For both of these use-cases we should be able to make new React components that can be placed on the map, containing only react-leaflet children.
Example code:
The above does not show the marker, and logs a warning:
The text was updated successfully, but these errors were encountered: