Portal to a node outside root react element

231 views Asked by At

I need to draw react (MUI) elements above fullscreen element (map in fullscreen mode) that is created dynamically in a body element.

I've managed to do so by creating a div directly in body with the following style:

    position: absolute;
    z-index: 100000;
    width: 100px;
    height: 100px;
    top: 0px;
    left: 0px;

The contents of this div appear above the map in fullscreen mode.

The map in fullscreen mode also dynamically creates its element in body.

But because this element is outside my map wrapper component and it is even outside react root node - I do not know how can I render mui components there.

I'm aware of Portal functionality but it needs a ref to the destination div.

How can I obtain this ref if the div is outside react root and is created dynamically or statically in index.html?

0

There are 0 answers