You need to enable JavaScript to run this app.

Isomorphic Portal

A wrapper for react portal that gives us a better API to deal with react portal in SSR applications.

Source

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);
}

Example

isomorphicPortal(<Div />, "#modal__wrapper");
Favourite Books
BooksPoems
Favourite Songs
PlaylistsArtists
Favourite Shows
AnimationsSeriesAnime