Portal
Mounts children into another DOM element, waiting until that element exists.
Usage
tsx
<Portal element={document.querySelector("[data-root]")}>
<Cursor />
</Portal>Into a ref
A ref is empty on the first render. Keep the node in state: Portal renders as soon as it arrives.
tsx
const [anchor, setAnchor] = useState<Element | null>(null);
<div ref={setAnchor} />
<Portal element={anchor}>
<Tooltip />
</Portal>rendered here, in the page
target:
Reference
| prop | type | default | |
|---|---|---|---|
element? | Element | null | null | the DOM node to render into |
children? | Renderable | — | rendered inside the target element |