import { Suspense, createElement, lazy, type ComponentType, type ReactNode } from "react"; type DynamicModule
= { default: ComponentType
} | ComponentType
; type DynamicOptions = { loading?: () => ReactNode; ssr?: boolean; }; export default function dynamic
(
loader: () => Promise {
const LazyComponent = lazy(async () => {
const mod = await loader();
return "default" in mod ? mod : { default: mod };
});
const DynamicComponent = (props: P) =>
createElement(
Suspense,
{ fallback: options.loading?.() ?? null },
createElement(LazyComponent as ComponentType