A wrapper for react portal that gives us a better API to deal with react portal in SSR applications.
import { createPortal } from "react-dom";
function isomorphicPortal(children, selector) {
const isClient = !!(
typeof window !== "undefined" &&
window.document &&
window.document.createElement
);
if (!isClient) return null;
const destEl = selector ? document.querySelector(selector) : null;
return createPortal(children, destEl || document.body);
}
isomorphicPortal(<Div />, "#modal__wrapper");