UNPKG

retro-react

Version:

A React component library for building retro-style websites

2 lines (1 loc) 572 B
import{useState as t,useRef as o,useEffect as e}from"react";import r from"react-dom";const i=i=>{let{children:d,position:l}=i;const[n,p]=t(!1),c=o(document.createElement("div"));return e((()=>{const t=c.current;return p(!0),document.body.appendChild(t),l&&(t.style.position="fixed",void 0!==l.top&&(t.style.top=`${l.top}px`),void 0!==l.bottom&&(t.style.bottom=`${l.bottom}px`),void 0!==l.left&&(t.style.left=`${l.left}px`),void 0!==l.right&&(t.style.right=`${l.right}px`)),()=>{document.body.removeChild(t)}}),[l]),n?r.createPortal(d,c.current):null};export{i as Portal};