File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed
Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import React, { Component } from 'react';
22
33const errorLoading = ( err ) => console . error ( 'AsyncComponent: Loading failed' , err ) ;
44const isFunction = ( func ) => Object . prototype . toString . call ( func ) === '[object Function]' ;
5+ const isPromise = ( obj ) => ! ! obj && ( typeof obj === 'object' || typeof obj === 'function' ) && typeof obj . then === 'function' ;
56
67export default ( loader , { placeholder } = { } ) => {
78 class AsyncComponent extends Component {
@@ -19,7 +20,13 @@ export default (loader, { placeholder } = {}) => {
1920 return console . error ( 'AsyncComponent: Loader is not function' ) ;
2021 }
2122
22- loader ( )
23+ const component = loader ( ) ;
24+
25+ if ( ! isPromise ( component ) ) {
26+ return console . error ( 'AsyncComponent: Loader return not promise' ) ;
27+ }
28+
29+ component
2330 . then ( ( module ) => this . mounting && this . setState ( { component : module . default } ) )
2431 . catch ( errorLoading ) ;
2532 }
You can’t perform that action at this time.
0 commit comments