structyl

Portal

stable

Renders children into document.body or a custom container.

Basic usage

Container:
Content is portalled into the container div above

Examples

Inline container portal

Portal renders children inside a specific DOM node — here visible within the preview.

Container:

Body portal

Without a container, Portal renders into document.body — useful for modals and overlays.

Content portalled to document.body exits this preview container — useful for z-index isolation.

Custom container

Portal renders into document.body by default; pass container for a specific node.

Container:

Features

  • SSR-safe mount.
  • Custom container support.

Installation

bash
pnpm dlx structyl add portal

API Reference

Portal

Portal utility.

PropTypeDefault
containerElement | DocumentFragment | null

Custom target container.

childrenReact.ReactNode

Portaled content.

Portal | structyl