I have a parent component with two children:
- a Leaflet map
- a list of locations visible on the map (calculated using the map's getBounds())
I'm having a problem initializing that list of locations. Some things I tried:
- I create a reference using
useRefin the parent of the two components and passing it the MapContainer via thereftag but it isn't initialized by the time the parent's useEffect happens. - I created a callback which I tried calling in
whenReadyto pass the bounds back to the parent, butwhenReadydoesn't have access to the Map Object. - I created a child of the
MapContainerto handle events. That child reacts to'load'and'moveend'and that works for when the map moves but doesn't run on first render. - I tried having the event handler component call a callback in the parent to trigger the redraw. But that causes a component update during a component update which isn't allowed.
So how do I trigger a callback in the parent with the bounds of the map after it is finished loading?