How to Fix React Portal createPortal Issues
DodaTech
Updated 2026-06-26
1 min read
The Problem
In this quick-fix, you'll learn how to use createPortal to render outside parent DOM tree. This matters because modals get clipped by parent overflow:hidden. In real-world applications, this pattern appears in modals tooltips context menus that render above all content.
The Wrong Way
function Modal({ children }) {
return <div className="modal">{children}</div>;
}
function App() {
return <div style={{overflow:'hidden'}}><Modal>Hello</Modal></div>;
}
Modal clipped by overflow:hidden
The Right Way
import { createPortal } from 'react-dom';
function Modal({ children }) {
return createPortal(<div className="modal">{children}</div>, document.body);
}
Modal renders at body end -- visible above all content
Prevention
- Pass valid DOM element as second argument
- Use document.body for top-level overlays
- Portal participates in React event tree
- Manage focus inside modal portals
FAQ
This guide is brought to you by DodaTech — built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro.
← Previous
How to Fix React Component Not Rendering
Next →
How to Fix React PropTypes Validation Errors
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro