Skip to content

Commit 8a3e7c0

Browse files
authored
Merge pull request #9255 from marmelab/demo-lazy
[Demo] Add lazy loading to CRM demo to illustrate code splitting
2 parents 092f420 + 9e8b7ef commit 8a3e7c0

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

examples/crm/src/Layout.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import React, { HtmlHTMLAttributes } from 'react';
1+
import React, { Suspense, HtmlHTMLAttributes } from 'react';
22
import { CssBaseline, Container } from '@mui/material';
33
import { CoreLayoutProps, CheckForApplicationUpdate } from 'react-admin';
44
import { ErrorBoundary } from 'react-error-boundary';
55

6-
import { Error } from 'react-admin';
6+
import { Error, Loading } from 'react-admin';
77
import Header from './Header';
88

99
const Layout = ({ children }: LayoutProps) => (
@@ -14,7 +14,7 @@ const Layout = ({ children }: LayoutProps) => (
1414
<main id="main-content">
1515
{/* @ts-ignore */}
1616
<ErrorBoundary FallbackComponent={Error}>
17-
{children}
17+
<Suspense fallback={<Loading />}>{children}</Suspense>
1818
</ErrorBoundary>
1919
</main>
2020
</Container>

examples/crm/src/deals/DealList.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { DealShow } from './DealShow';
1717
import { OnlyMineInput } from './OnlyMineInput';
1818
import { typeChoices } from './types';
1919

20-
export const DealList = () => {
20+
const DealList = () => {
2121
const { identity } = useGetIdentity();
2222
const location = useLocation();
2323
const matchCreate = matchPath('/deals/create', location.pathname);
@@ -61,3 +61,5 @@ const DealActions = () => {
6161
</TopToolbar>
6262
);
6363
};
64+
65+
export default DealList;

examples/crm/src/deals/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-disable import/no-anonymous-default-export */
2-
import { DealList } from './DealList';
2+
import * as React from 'react';
3+
const DealList = React.lazy(() => import('./DealList'));
34

45
export default {
56
list: DealList,

0 commit comments

Comments
 (0)