Skip to content

Commit

Permalink
[๐Ÿ’Ž : refactor] Lazy Loading ์ ์šฉ (#12)
Browse files Browse the repository at this point in the history
- ๋ฉ”์ธ ํŽ˜์ด์ง€์— ์ ‘์†ํ•  ๋•Œ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ์ปดํฌ๋„ŒํŠธ๋“ค๊นŒ์ง€ ๋จผ์ € ๋กœ๋“œ์‹œํ‚ค์ง€ ์•Š๊ธฐ ์œ„ํ•ด ์ ์šฉ
- Lazy Loading์ด ์ ์šฉ๋œ ์ปดํฌ๋„ŒํŠธ๋Š” ๋นŒ๋“œ ์‹œ, ๋ณ„๋„์˜ js ํŒŒ์ผ๋กœ ๋ถ„๋ฆฌ๋จ
  • Loading branch information
sryung1225 committed Dec 19, 2023
1 parent 6e0bbb6 commit 395bd39
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { useEffect, useState } from 'react';
import { useEffect, useState, lazy, Suspense } from 'react';
import { RouterProvider, createBrowserRouter } from 'react-router-dom';
import { auth } from './firebase.ts';
import ProtectedRoute from './components/protected-route.tsx';
import Home from './routes/home.tsx';
import Profile from './routes/profile.tsx';
import SearchResult from './routes/search-result.tsx';
import Auth from './routes/auth.tsx';
import Layout from './components/layout.tsx';
import LoadingSpinner from './components/loading-spinner.tsx';
import * as S from './styles/global.ts';

const ProtectedRoute = lazy(() => import('./components/protected-route.tsx'));
const Home = lazy(() => import('./routes/home.tsx'));
const Profile = lazy(() => import('./routes/profile.tsx'));
const SearchResult = lazy(() => import('./routes/search-result.tsx'));
const Auth = lazy(() => import('./routes/auth.tsx'));
const Layout = lazy(() => import('./components/layout.tsx'));
const LoadingSpinner = lazy(() => import('./components/loading-spinner.tsx'));

const router = createBrowserRouter([
{
path: '/',
Expand Down Expand Up @@ -51,7 +52,9 @@ function App() {
return (
<>
<S.GlobalStyles />
{isLoading ? <LoadingSpinner /> : <RouterProvider router={router} />}
<Suspense fallback={<LoadingSpinner />}>
{isLoading ? <LoadingSpinner /> : <RouterProvider router={router} />}
</Suspense>
</>
);
}
Expand Down

0 comments on commit 395bd39

Please sign in to comment.