Portal.tsx 339 B

1234567891011121314
  1. import React from 'react'
  2. import { createPortal } from 'react-dom'
  3. type PortalProps = {
  4. containerRef: React.RefObject<HTMLDivElement>
  5. }
  6. export const Portal: React.FC<PortalProps> = ({ children, containerRef }) => {
  7. const element = containerRef.current
  8. if (!element) {
  9. return null
  10. }
  11. return createPortal(children, element)
  12. }