Skip to content

Commit

Permalink
spit codes to lazy loading to improve the performance
Browse files Browse the repository at this point in the history
  • Loading branch information
TrumanH committed Jan 12, 2023
1 parent 6954572 commit 7e78c94
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
26 changes: 15 additions & 11 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { useEffect } from 'react';
import { useEffect, lazy, Suspense } from 'react';
import { Routes, Route } from 'react-router-dom';
import Home from './routes/home/home.component';
import Navigation from './routes/navigation/navigation.component';
import Authentication from './routes/authentication/authentication.component';
import Shop from './routes/shop/shop.component';
import Checkout from './routes/checkout/checkout.component';
import { onAuthStateChangeListener, createUserDocumentFromAuth } from './utils/firebase/firebase.utils';
import { useDispatch } from 'react-redux';
import { setUser } from './store/user/user.slice';
import Spinner from './components/spinner/spinner.component';

const Shop = lazy(()=> import('./routes/shop/shop.component'));
const Authentication = lazy(()=>import('./routes/authentication/authentication.component'));

const App = ()=> {
const dispatch = useDispatch();
Expand All @@ -29,14 +31,16 @@ const App = ()=> {
}, [dispatch]);

return (
<Routes>
<Route path="/" element={<Navigation />}>
<Route index element={<Home/>} />
<Route path='shop/*' element={<Shop />} />
<Route path='auth' element={<Authentication />} />
<Route path='checkout' element={<Checkout />} />
</Route>
</Routes>
<Suspense callback={<Spinner />}>
<Routes>
<Route path="/" element={<Navigation />}>
<Route index element={<Home/>} />
<Route path='shop/*' element={<Shop />} />
<Route path='auth' element={<Authentication />} />
<Route path='checkout' element={<Checkout />} />
</Route>
</Routes>
</Suspense>
);
}

Expand Down
2 changes: 0 additions & 2 deletions src/components/cart-item/cart-item.component.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


import { FC, memo } from 'react';
import { CartItemContainer, ItemDetails, Text } from './cart-item.styles';
import { CartItem as CartItemT } from '../../store/cart/cart.slice';
Expand Down

0 comments on commit 7e78c94

Please sign in to comment.