jumpinjackie / mapguide-react-layout

An openlayers-based modern map viewer for MapGuide
https://jumpinjackie.github.io/mapguide-react-layout/
MIT License
62 stars 13 forks source link

useMapProviderContext hook unusable in custom components #1480

Open jumpinjackie opened 1 year ago

jumpinjackie commented 1 year ago

The useMapProviderContext hook in its current form is mostly un-usable because the context provider component for this hook is not mounted at a high-enough level where custom components will be a descendant component. These custom components will either be siblings with the context provider or their parent components are siblings, so the hook when called from a custom component will be a (default, un-initialized) viewer instance.

To fix this, we need to mount this context provider component at a higher level, preferably as a direct child of the root <App> component (or <AppInner>). However, relocating mount point is probably not trivial as the context provider is tightly coupled to init-ing the OpenLayers against a physical DOM element.

An alternative solution could be to leverage React portals so that we don't require context provider and context consumer with direct physical DOM parentage of their respective components.

jumpinjackie commented 1 year ago

If react portals is a feasible and workable solution, then we can re-target the milestone to 0.14