|
@@ -16,40 +16,20 @@ type Props<C extends ComponentType> = Omit<React.ComponentProps<C>, 'route'> & {
|
|
|
/**
|
|
|
* Accepts a function to trigger the import resolution of the component.
|
|
|
*/
|
|
|
- component?: () => PromisedImport<C>;
|
|
|
- /**
|
|
|
- * Accepts a route object from react-router that has a `componentPromise` property
|
|
|
- */
|
|
|
- route?: {componentPromise: () => PromisedImport<C>};
|
|
|
+ component: () => PromisedImport<C>;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* LazyLoad is used to dynamically load codesplit components via a `import`
|
|
|
- * call. Typically this component is used as part of the routing tree, though
|
|
|
- * it does have a standalone mode.
|
|
|
- *
|
|
|
- * Route tree usage:
|
|
|
- * <Route
|
|
|
- * path="somePath"
|
|
|
- * component={LazyLoad}
|
|
|
- * componentPromise={() => import('./somePathView')}
|
|
|
- * />
|
|
|
+ * call. This is primarily used in our routing tree.
|
|
|
*
|
|
|
- * Standalone usage:
|
|
|
- * <LazyLoad component={() => import('./myComponent')} someComponentProps={...} />
|
|
|
+ * <LazyLoad component={() => import('./myComponent')} someComponentProps={...} />
|
|
|
*/
|
|
|
function LazyLoad<C extends ComponentType>(props: Props<C>) {
|
|
|
- const importComponent = props.component ?? props.route?.componentPromise;
|
|
|
+ const importComponent = props.component;
|
|
|
|
|
|
const LazyComponent = useMemo(
|
|
|
- () =>
|
|
|
- lazy(() => {
|
|
|
- if (!importComponent) {
|
|
|
- throw new Error('No component to load');
|
|
|
- }
|
|
|
-
|
|
|
- return retryableImport(importComponent);
|
|
|
- }),
|
|
|
+ () => lazy(() => retryableImport(importComponent)),
|
|
|
[importComponent]
|
|
|
);
|
|
|
|