/* global document */
import React from "react";
import ReactDOM from "react-dom";

type PortalProps = {
  id?: string;
  children: React.ReactNode;
};

const Portal = ({ children, id = "portal" }: PortalProps) => {
  if (typeof window === "undefined") {
    return null;
  }

  return ReactDOM.createPortal(children, document.querySelector(`#${id}`));
};

export default Portal;
