UNPKG

@feedma/react-gen-ui-resolver

Version:

A react js version for dynamic resolution of gen ui components

36 lines (35 loc) 1.17 kB
import { jsx as r } from "react/jsx-runtime"; import { Suspense as a, lazy as m } from "react"; const s = async () => { const e = await import("__federation__"); return e.__federation_method_getRemote && e.__federation_method_setRemote ? { getRemote: e.__federation_method_getRemote, setRemote: e.__federation_method_setRemote } : null; }, d = ({ url: e, name: o, module: n }) => m(async () => { const t = await s(); if (!t) throw new Error( "Module federation is not configured. Please ensure @originjs/vite-plugin-federation is properly set up in your host application. The host application must configure the federation plugin and expose the federation runtime." ); return t.setRemote(o, { url: () => Promise.resolve(e), format: "esm", from: "vite" }), t.getRemote(o, n); }), u = ({ url: e, name: o, module: n, props: t }) => /* @__PURE__ */ r(a, { fallback: /* @__PURE__ */ r("div", { children: "Loading remote component..." }), children: (() => { const i = d({ url: e, name: o, module: n }); return /* @__PURE__ */ r(i, { ...t }); })() }); export { u as DynamicRemoteComponentLoader };