UNPKG

1.6 kBSource Map (JSON)View Raw
1{"version":3,"sources":["../../../client/portal/index.tsx"],"names":["Portal","children","type","portalNode","React","useRef","forceUpdate","useState","useEffect","current","document","createElement","body","appendChild","removeChild"],"mappings":"gJAAA,oDACA,mCAOO,KAAMA,CAAAA,MAA6B,CAAG,CAAC,CAAEC,QAAF,CAAYC,IAAZ,CAAD,GAAwB,CACnE,GAAIC,CAAAA,UAAU,CAAGC,KAAK,CAACC,MAAN,CAAiC,IAAjC,CAAjB,CACA,GAAI,EAAGC,WAAH,EAAkBF,KAAK,CAACG,QAAN,EAAtB,CACAH,KAAK,CAACI,SAAN,CAAgB,IAAM,CACpBL,UAAU,CAACM,OAAX,CAAqBC,QAAQ,CAACC,aAAT,CAAuBT,IAAvB,CAArB,CACAQ,QAAQ,CAACE,IAAT,CAAcC,WAAd,CAA0BV,UAAU,CAACM,OAArC,EACAH,WAAW,CAAC,EAAD,CAAX,CACA,MAAO,IAAM,CACX,GAAIH,UAAU,CAACM,OAAf,CAAwB,CACtBC,QAAQ,CAACE,IAAT,CAAcE,WAAd,CAA0BX,UAAU,CAACM,OAArC,EACD,CACF,CAJD,CAKD,CATD,CASG,CAACP,IAAD,CATH,EAWA,MAAOC,CAAAA,UAAU,CAACM,OAAX,cAAqB,2BAAaR,QAAb,CAAuBE,UAAU,CAACM,OAAlC,CAArB,CAAkE,IAAzE,CACD,CAfM,C","sourcesContent":["import * as React from 'react'\nimport { createPortal } from 'react-dom'\n\ntype PortalProps = {\n children: React.ReactNode\n type: string\n}\n\nexport const Portal: React.FC<PortalProps> = ({ children, type }) => {\n let portalNode = React.useRef<HTMLElement | null>(null)\n let [, forceUpdate] = React.useState<{}>()\n React.useEffect(() => {\n portalNode.current = document.createElement(type)\n document.body.appendChild(portalNode.current)\n forceUpdate({})\n return () => {\n if (portalNode.current) {\n document.body.removeChild(portalNode.current)\n }\n }\n }, [type])\n\n return portalNode.current ? createPortal(children, portalNode.current) : null\n}\n"]}
\No newline at end of file