import React, { createElement } from "react";
import ReactDOM from "react-dom";

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

let isLoaded = false;

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

  return { registerPortal, removePortal, React };
}
