Skip to content

Commit 904353c

Browse files
committed
new checked to loader return not promise
1 parent 47c472a commit 904353c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/AsyncComponent.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { Component } from 'react';
22

33
const errorLoading = (err) => console.error('AsyncComponent: Loading failed', err);
44
const 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

67
export 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
}

0 commit comments

Comments
 (0)