@@ -24,23 +24,34 @@ interface ImportedShape<T> {
2424 retry ( ) : void ;
2525}
2626
27- export function useLoadable < T > ( loadable : Loadable < T > ) {
28- if ( isBackend && ! isItReady ( ) ) {
29- console . error ( 'react-imported-component: trying to render not ready component. Have you `await whenComponentsReady()`?' )
30- }
27+ interface HookOptions {
28+ import ?: boolean ;
29+ track ?: boolean ;
30+ }
3131
32+ export function useLoadable < T > ( loadable : Loadable < T > , options : HookOptions = { } ) {
3233 const UID = useContext ( streamContext ) ;
3334 const [ , forceUpdate ] = useState ( ( ) => {
3435 // use mark
35- useMark ( UID , loadable . mark ) ;
36- loadable . loadIfNeeded ( ) ;
36+ if ( options . import !== false ) {
37+ if ( options . track !== false ) {
38+ useMark ( UID , loadable . mark ) ;
39+ }
40+ loadable . loadIfNeeded ( ) ;
41+ }
3742
3843 return { } ;
3944 } ) ;
4045
4146 useEffect ( ( ) => {
42- loadLoadable ( loadable , forceUpdate ) ;
43- } , [ loadable ] ) ;
47+ if ( options . import !== false ) {
48+ loadLoadable ( loadable , forceUpdate ) ;
49+ }
50+ } , [ loadable , options . import ] ) ;
51+
52+ if ( isBackend && ! isItReady ( ) && loadable . isLoading ( ) ) {
53+ console . error ( 'react-imported-component: trying to render not ready component. Have you `await whenComponentsReady()`?' )
54+ }
4455
4556 // use mark
4657 // retry
@@ -54,8 +65,8 @@ export function useLoadable<T>(loadable: Loadable<T>) {
5465 } , [ loadable ] ) ;
5566
5667 if ( process . env . NODE_ENV !== 'production' ) {
57- if ( isBackend ) {
58- if ( ! loadable . done ) {
68+ if ( isBackend ) {
69+ if ( ! loadable . done ) {
5970 console . error ( 'react-imported-component: using not resolved loadable. You should `await whenComponentsReady()`.' )
6071 }
6172 }
@@ -68,14 +79,14 @@ export function useLoadable<T>(loadable: Loadable<T>) {
6879 } ;
6980}
7081
71- export function useImported < T , K = T > ( importer : DefaultImport < T > | Loadable < T > , exportPicker : ( x : T ) => K = es6import ) : ImportedShape < K > {
82+ export function useImported < T , K = T > ( importer : DefaultImport < T > | Loadable < T > , exportPicker : ( x : T ) => K = es6import , options : HookOptions = { } ) : ImportedShape < K > {
7283 const [ topLoadable ] = useState ( getLoadable ( importer ) ) ;
7384 const postEffectRef = useRef ( false ) ;
7485 const {
7586 loadable,
7687 retry,
7788 update,
78- } = useLoadable < T > ( topLoadable ) ;
89+ } = useLoadable < T > ( topLoadable , options ) ;
7990
8091 // kick loading effect
8192 useEffect ( ( ) => {
0 commit comments