UNPKG

@yz-dev/react-dynamic-module

Version:

A powerful React component for dynamically loading premium or optional modules from a script URL with dependency injection.

22 lines (20 loc) 1.09 kB
import { default as React } from 'react'; type DynamicModuleBaseProps = { /** The name of the exported component property within the global variable. */ import: string; /** The name of the global variable the script attaches to the window object. */ from: string; /** The public path to the self-contained JavaScript module. */ src: string; /** Optional: A React component to show while loading. Defaults to null. */ loadingUi?: React.ReactNode; /** Optional: A React component to show if loading fails. Defaults to null. */ errorUi?: React.ReactNode; /** Optional: An object of dependencies to inject into the window scope for the script to use. React and ReactDOM are always included. */ dependencies?: Record<string, any>; /** Optional: A callback function to handle errors. */ onError?: (error: Error) => void; }; export type DynamicModuleProps<P extends object> = DynamicModuleBaseProps & P; export declare const DynamicModule: <P extends object>(props: DynamicModuleProps<P>) => import("react/jsx-runtime").JSX.Element; export {};