PortalProvider API
- Component status:
stable
Import
Section titled “Import”import { PortalProvider } from "@stratakit/mui";PortalProvider
Section titled “PortalProvider”Provides the PortalContext to its children and sets up the MUI theme provider.
All descendent floating elements from StrataKit and MUI will be portaled into the specified container.
Example:
const [container, setContainer] = React.useState(null);
<CustomDialog ref={setContainer}> <PortalProvider container={container}> … </PortalProvider></CustomDialog>container
Section titled “container”Type:
HTMLElement | null (required)The element to which all portals will be rendered.
children
Section titled “children”Type:
ReactNode (optional)unstable_getContainer
Section titled “unstable_getContainer”Type:
(() => HTMLElement | null) | undefined (optional)Function that is lazily resolved by MUI when the portal mounts. Passing the
element directly requires the theme to be recreated once the element becomes available, which
leaves a one-commit window where portals fall back to <body>.
Needed to workaround https://github.com/mui/material-ui/issues/48882