Skip to content

LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows

1.0 KB
Raw Blame
import { lazy } from "react";

// Lazy-load a module's NAMED export as a route component. React.lazy expects a
// module with a `default` export, so this adapts `{ Foo }` to `{ default: Foo }`.
// Use it to code-split route pages/layouts that use named exports without
// repeating the `.then((m) => ({ default: m.X }))` boilerplate at every site.
//
// For DEFAULT-exported components, use `lazy(() => import(...))` directly.
// For OPTIONAL enterprise plugins that may be absent in OSS, use `lazyPlugin`
// (pluginRegistry.js) instead — it adds the missing-plugin NotFound fallback.
export function lazyNamed(loader, exportName) {
  return lazy(() =>
    loader().then((m) => {
      const component = m?.[exportName];
      if (!component) {
        // Fail loudly with the offending name instead of handing React.lazy
        // `{ default: undefined }`, which surfaces as an opaque render error.
        throw new Error(`lazyNamed: module has no export "${exportName}"`);
      }
      return { default: component };
    }),
  );
}