
New
createPortal (React)
Using the react dom create portal to lift dom elements into the root.
reactreact-dom
## Requirements
React's createPortal
API allows you to render elements outside of their parent component’s DOM hierarchy. This is especially useful when dealing with UI elements like modals, tooltips, dropdowns, and overlays that must break out of the normal rendering flow.
## 📦 Requirements
To use createPortal
, make sure your project meets these requirements:
- React 16 or higher
react-dom
installed- An additional DOM node (e.g. a
div#modal-root
) defined in your base HTML
Install React and ReactDOM if you haven't already:
npm install react react-dom
pnpm add react react-dom
yarn add react react-dom
bun add react react-dom
Published on July 1, 2025
1 min read
Found an Issue!
Find an issue with this post? Think you could clarify, update or add something? All my posts are available to edit on Github. Any fix, little or small, is appreciated!
Edit on GitHub