import React, { createElement } from "react";
import { createRoot } from "react-dom/client";

import {
  setRenderHelper,
  registerPortal,
  removePortal,
} from "./injectedReactShimShared";

let isLoaded = false;

export function loadReact(rootEl) {
  if (!isLoaded) {
    const root = createRoot(rootEl);
    root.render(createElement(React.Fragment));
    setRenderHelper((component) => root.render(component));
    isLoaded = true;
  }

  return { registerPortal, removePortal, React };
}
