0
Challenge · 38Hooks & Effects

Portals

Coreused in ~55% of apps

You build a modal deep inside a card that has overflow:hidden — and the modal gets clipped, sits under a sibling because of z-index, or jumps around because a parent has transform. No CSS hack fully fixes it. Portals let the modal render straight into <body> so nothing can clip or stack it.

Core idea. createPortal(children, domNode) renders children into a DIFFERENT place in the real DOM (often document.body) while keeping them in the SAME position in the React tree — so state, context, and event bubbling all behave as if they were a normal child.
Playground, this isn't a screenshot
rendered result
<body>
<Card overflow:hidden>z-index trap
A card that clips its overflow.
react tree
<App>
└<Card>

Always a child of <Card>.

dom tree
<body>
└#root
└div.card

Physically wherever it's rendered.

Portal OFF. Open the modal — it renders inside the overflow:hidden box and gets clipped.
↑ play a little first, then dig in