Unable to add ref to Map component
Please make sure to check the following boxes before submitting an issue. Thanks!
- [x] All peer dependencies are installed: React, ReactDOM and Leaflet.
- [x] Using a supported version of React and ReactDOM (v15.x).
- [x] Using the supported version of Leaflet (v1.x) and its corresponding CSS file is loaded.
- [x] Using the latest version of React-Leaflet.
- [x] The issue has not already been reported.
- [x] Make sure you have followed the quick start guide for Leaflet.
- [x] Make sure you have fully read the documentation and that you understand the technical considerations.
Expected behavior
I should be able to add a ref to the Map component in order to get the underlying Leaflet object.
Actual behavior
Attempting to add a ref property results in:
Only a ReactOwner can have refs. You might be adding a ref to a component that was not created
inside a component's `render` method, or you have multiple copies of React loaded
(details: https://fb.me/react-refs-must-have-owner).
The <Map ref="map" /> component is being rendered inside of a render method and I only have one copy of React loaded. I'm able to add refs to all parent components, and use them extensively in my project. The Map component is the only component that I cannot add a ref to without getting an error.
Is there any other way to get the underlying Leaflet object?
ref works as expected, whatever issue you're having is most likely coming from your code, please provide an example using webpackbin or similar if it's not.
I'm sure something is going on, but I can't track it down. Is there any other way to get the underlying Leaflet object? Without the Leaflet object I can't invalidate the size properly, get visible markers, etc.
Not sure why, but the callback version of ref works while the string version throws the error.