paint-brush
How to Transport Your Components Anywhere With React Portalsby@smpnjn
1,872 reads
1,872 reads

How to Transport Your Components Anywhere With React Portals

by Johnny Simpson5mOctober 12th, 2022
Read on Terminal Reader
Read this story w/o Javascript

Too Long; Didn't Read

When we create components in React, normally they exist within the component tree. This is mostly fine, but sometimes we want certain parts of a component to appear outside the tree. Using `createPortal, we can teleport the modal out of its own component and into another part of our template. This allows us to put our component anywhere we desire else, like the base of the HTML tree, inside the `body` tag, or inside another element. Using React Portals is pretty easy to create a portal.

Company Mentioned

Mention Thumbnail
featured image - How to Transport Your Components Anywhere With React Portals
Johnny Simpson HackerNoon profile picture
Johnny Simpson

Johnny Simpson

@smpnjn

Product, Engineering, Web

About @smpnjn
LEARN MORE ABOUT @SMPNJN'S
EXPERTISE AND PLACE ON THE INTERNET.
L O A D I N G
. . . comments & more!

About Author

Johnny Simpson HackerNoon profile picture
Johnny Simpson@smpnjn
Product, Engineering, Web

TOPICS

Languages

THIS ARTICLE WAS FEATURED IN...

Permanent on Arweave
Read on Terminal Reader
Read this story in a terminal
 Terminal
Read this story w/o Javascript
Read this story w/o Javascript
 Lite
Also published here