Access context in promise-based modal (React)

334 Views Asked by At

I have a modal service that returns a promise, so consuming components can await on the modal's confirmation. Because the modal is added to the html body, outside the app root component that adds the context wrappers, it has no access to the context. As I understand it the only way to access context from the outside is to use portals. I've tried this but it's not working.

As far as I can tell there is no way to render a portal programatically without using the render method, but when I use this method the result seems to be the same as not using portals at all.

Code sample: showing a button just to exemplify the issue

https://codesandbox.io/s/fancy-tree-1e6m1?file=/index.js

I need to access the theme provided by the theme context provider from the modal component so the theme is inherited.

0

There are 0 best solutions below