Skip to main content

Function: createPortal()

createPortal(children, container, key?): ReactPortal

Defined in: portal.ts:29

Creates a React portal for rendering children into a different part of the widget tree.

Portals are useful for rendering dialogs, tooltips, or other floating content that should visually appear outside its parent component's boundaries.

Parameters

ParameterTypeDescription
childrenReactNodeThe React elements to render in the portal
containerContainerThe target container widget to render into
key?string | nullOptional key for the portal element

Returns

ReactPortal

A ReactPortal element

Example

import { createPortal } from "@gtkx/react";

const Modal = ({ container, children }) => {
return createPortal(
<GtkWindow modal>
{children}
</GtkWindow>,
container
);
};