Web Development React.js Subjective
Sep 28, 2025

What are React portals and their use cases?

Detailed Explanation

Portals render children into a DOM node outside the parent component hierarchy. Use cases include modals, tooltips, dropdowns.

import { createPortal } from "react-dom";

function Modal({ children, isOpen }) {
  if (!isOpen) return null;
  
  return createPortal(
    <div className="modal-overlay">
      <div className="modal">
        {children}
      </div>
    </div>,
    document.getElementById("modal-root")
  );
}
Discussion (0)

No comments yet. Be the first to share your thoughts!

Share Your Thoughts
Feedback