Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Allow for named imports in React.lazy
  • Loading branch information
gnestor committed Jan 16, 2019
commit 220dc2c929ba3e45fd21cf47dad52b5410feccf4
14 changes: 8 additions & 6 deletions packages/react-reconciler/src/ReactFiberLazyComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,24 @@ export function readLazyComponentType<T>(lazyComponent: LazyComponent<T>): T {
const ctor = lazyComponent._ctor;
const thenable = ctor();
thenable.then(
moduleObject => {
resolvedComponent => {
if (lazyComponent._status === Pending) {
const defaultExport = moduleObject.default;
if (resolvedComponent.default) {
resolvedComponent = resolvedComponent.default;
}
if (__DEV__) {
if (defaultExport === undefined) {
if (resolvedComponent === undefined) {
warning(
false,
'lazy: Expected the result of a dynamic import() call. ' +
'lazy: Expected a promise that resolves to a React component. ' +
'Instead received: %s\n\nYour code should look like: \n ' +
"const MyComponent = lazy(() => import('./MyComponent'))",
moduleObject,
resolvedComponent,
);
}
}
lazyComponent._status = Resolved;
lazyComponent._result = defaultExport;
lazyComponent._result = resolvedComponent;
}
},
error => {
Expand Down