UNPKG

rasengan

Version:

The modern React Framework

22 lines (21 loc) 742 B
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime"; import { Suspense, lazy } from 'react'; /** * It allows you to defer loading of Client Components, * and only include them in the client bundle when they're needed * @param load * @param fallback * @returns */ export function dynamicLoad(load, fallback = _jsx(_Fragment, {}) // Default pending UI element ) { try { const LazyComponent = lazy(load); // Return a functional component preserving the exact props type const WrappedComponent = (props) => (_jsx(Suspense, { fallback: fallback, children: _jsx(LazyComponent, { ...props }) })); return WrappedComponent; } catch (error) { throw new Error(error); } }