Spaces:
Sleeping
Sleeping
| // Portal.jsx | |
| // Renders children directly into document.body, escaping any | |
| // parent overflow / transform / stacking-context restrictions. | |
| "use client"; | |
| import { useEffect, useRef } from "react"; | |
| import { createPortal } from "react-dom"; | |
| export default function Portal({ children }) { | |
| const elRef = useRef(null); | |
| if (!elRef.current && typeof document !== "undefined") { | |
| elRef.current = document.createElement("div"); | |
| } | |
| useEffect(() => { | |
| const el = elRef.current; | |
| if (!el) return; | |
| document.body.appendChild(el); | |
| return () => { | |
| document.body.removeChild(el); | |
| }; | |
| }, []); | |
| if (!elRef.current) return null; | |
| return createPortal(children, elRef.current); | |
| } |