Skip to content

Commit

Permalink
add lazy loading example
Browse files Browse the repository at this point in the history
  • Loading branch information
rwieruch committed Apr 20, 2022
1 parent 061bb14 commit e68bad1
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 1 deletion.
57 changes: 57 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"serve": "vite preview"
},
"dependencies": {
"@loadable/component": "^5.15.2",
"history": "^5.1.0",
"query-string": "^7.0.1",
"react": "^17.0.0",
Expand Down
49 changes: 49 additions & 0 deletions src/App.LazyLoading.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import * as React from 'react';
import { Routes, Route, Link } from 'react-router-dom';
import loadable from '@loadable/component';

const Home = loadable(() => import('./pages/Home'), {
resolveComponent: (components) => components.Home,
});

const About = loadable(() => import('./pages/About'), {
resolveComponent: (components) => components.About,
});

const App = () => {
return (
<>
<h1>React Router</h1>

<nav>
<Link to="/">Home</Link>
<Link to="/about">About</Link>
</nav>

<Routes>
<Route index element={<Home />} />
<Route path="about" element={<About />} />
<Route path="*" element={<NoMatch />} />
</Routes>
</>
);
};

const NoMatch = () => {
return <p>There's nothing here: 404!</p>;
};

export default App;

// import loadable from '@loadable/component';

// import * as ROUTES from '@/constants/routes';
// import { Page } from '@/components/Layout/Page';

// import { Navigation } from './Navigation';

// const ReviewKpis = loadable(() => import('./ReviewKpis'), {
// resolveComponent: (components) => {
// return components.ReviewKpis;
// },
// });
3 changes: 2 additions & 1 deletion src/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import { QueryParamProvider } from 'use-query-params';

// import App from './App.jsx';
// import App from './App.Redirect.jsx';
import App from './App.Authentication.jsx';
// import App from './App.Authentication.jsx';
// import App from './App.Nested.jsx';
// import App from './App.Descendant.jsx';
// import App from './App.QueryParams.jsx';
import App from './App.LazyLoading.jsx';

// use-query-params adapeter for React Router 6
const RouteAdapter = ({ children }) => {
Expand Down
7 changes: 7 additions & 0 deletions src/pages/About.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const About = () => {
return (
<>
<h2>About</h2>
</>
);
};
7 changes: 7 additions & 0 deletions src/pages/Home.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const Home = () => {
return (
<>
<h2>Home</h2>
</>
);
};

0 comments on commit e68bad1

Please sign in to comment.