Skip to content

PortalProvider API

import { PortalProvider } from "@stratakit/mui";

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>
Type: HTMLElement | null (required)

The element to which all portals will be rendered.

Type: ReactNode (optional)
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