In a typical Roact tree every component’s output is placed inside its parent’s Instance. Portals break that rule intentionally: a portal renders its children into a different Roblox Instance that you specify, regardless of where the portal component sits in the component tree. This is especially useful for full-screen UI layers, global overlays, and any case where a component deep in the tree needs to own an object that must live somewhere else in the DataModel.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Roblox/roact/llms.txt
Use this file to discover all available pages before exploring further.
Creating a Portal
UseRoact.Portal as the first argument to Roact.createElement. The target prop must be a Roblox Instance that will become the parent of the portal’s children.
PartInWorkspace is mounted — no matter how deeply nested it is in the Roact tree — Roact creates a Part named SomePart directly inside Workspace. When PartInWorkspace unmounts, Roact removes that Part.
Use Case: Full-Screen Modal Dialogs
Portals shine when a component deep inside the tree needs to display a full-screen overlay. Without portals you would have to thread aScreenGui up through every layer of the hierarchy. With a portal the Modal component handles everything itself.
The Modal Component
The ModalButton Stateful Component
ModalButton keeps a small piece of state — whether the dialog is currently open — and conditionally renders the Modal component.
ModalButton, dialogOpen becomes true, Roact renders the Modal component, and the portal inserts a ScreenGui into PlayerGui — covering the entire screen. Clicking the overlay fires onClose, sets dialogOpen back to false, and Roact removes the ScreenGui from PlayerGui automatically.
How Roact Handles Portal Lifecycle
Roact treats portal children like any other managed subtree:- On mount — children are created as descendants of
target. - On update — children are reconciled in place inside
target, following the same rules as a normal subtree. - On unmount — all children created by the portal are destroyed.