@@ -15,12 +15,12 @@ import DefaultErrorComponent from './default-error-component';
1515import { PrefetchProvider } from './prefetch-context' ;
1616import { useScalprum } from './use-scalprum' ;
1717
18- // eslint-disable-next-line @typescript-eslint/ban-types
1918export type ScalprumComponentProps < API extends Record < string , any > = { } , Props extends Record < string , any > = { } > = Props & {
2019 fallback ?: NonNullable < React . ReactNode > | null ;
2120 api ?: API ;
2221 scope : string ;
2322 module : string ;
23+ importName ?: string ;
2424 ErrorComponent ?: React . ReactElement ;
2525 LoadingComponent ?: React . ComponentType ;
2626 innerRef ?: React . Ref < unknown > ;
@@ -36,6 +36,7 @@ async function setComponentFromModule(
3636 scope : string ,
3737 module : string ,
3838 isMounted : boolean ,
39+ importName : string ,
3940 setComponent : React . Dispatch <
4041 React . SetStateAction <
4142 | React . ComponentType < {
@@ -45,7 +46,7 @@ async function setComponentFromModule(
4546 >
4647 >
4748) : Promise < PrefetchFunction | undefined > {
48- const { prefetch, component } = await loadComponent ( scope , module ) ;
49+ const { prefetch, component } = await loadComponent ( scope , module , importName ) ;
4950 isMounted && setComponent ( ( ) => component ) ;
5051 return prefetch ;
5152}
@@ -58,6 +59,7 @@ const LoadModule: React.ComponentType<LoadModuleProps> = ({
5859 processor,
5960 innerRef,
6061 skipCache = false ,
62+ importName = 'default' ,
6163 ...props
6264} ) => {
6365 const { manifestLocation } = getAppData ( scope ) ;
@@ -103,7 +105,7 @@ const LoadModule: React.ComponentType<LoadModuleProps> = ({
103105 if ( manifestLocation ) {
104106 const processPromise = processManifest ( manifestLocation , scope , module , processor )
105107 . then ( ( ) => {
106- pref = setComponentFromModule ( scope , module , isMounted , setComponent ) ;
108+ pref = setComponentFromModule ( scope , module , isMounted , importName , setComponent ) ;
107109 pref . then ( ( result ) => {
108110 if ( result ) {
109111 const prefetch = getPendingPrefetch ( prefetchID ) || result ( scalprumApi ) ;
@@ -120,7 +122,7 @@ const LoadModule: React.ComponentType<LoadModuleProps> = ({
120122 }
121123 } else {
122124 try {
123- isMounted && setComponent ( ( ) => cachedModule . default ) ;
125+ isMounted && setComponent ( ( ) => cachedModule [ importName ] ) ;
124126
125127 pref = cachedModule . prefetch ;
126128 if ( pref ) {
@@ -186,7 +188,7 @@ class BaseScalprumComponent extends React.Component<ScalprumComponentProps, Base
186188 return ! isEqual ( nextProps , this . props ) || ! isEqual ( nextState , this . state ) ;
187189 }
188190
189- // TODO: Use ErrorWithCause once the type is avaiable
191+ // TODO: Use ErrorWithCause once the type is available
190192 componentDidCatch ( error : any , errorInfo : React . ErrorInfo ) {
191193 if ( this . selfRepairAttempt === true ) {
192194 console . error ( 'Scalprum encountered an error!' , error ?. cause || error . message , error ) ;
0 commit comments