-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.js
102 lines (97 loc) · 2.64 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import React, { lazy, Suspense, useState } from "react";
import ReactDOM from "react-dom/client";
import "./index.css";
import Header from "./src/Components/Header";
import Body from "./src/Components/Body";
import Footer from "./src/Components/Footer";
import Error from "./src/Components/Error";
import Contact from "./src/Components/Contact";
import { createBrowserRouter, RouterProvider, Outlet } from "react-router-dom";
import UserContext from "./src/utils/UserContext";
import { Provider } from "react-redux";
import store from "./src/utils/store";
import Cart from "./src/Components/Cart";
import Help from "./src/Components/Help";
import ShimmerMenu from "./src/Components/ShimmerMenu";
import ShimmerInstamart from "./src/Components/ShimmerInstamart";
import ShimmerAbout from "./src/Components/ShimmerAbout";
import LogIn from "./src/Components/Login";
// Chunking -- Code Splitting -- Dynamic Bundling -- Lazy Loading -- On Demand Loading -- Dynamic Import
const Instamart = lazy(() => import("./src/Components/Instamart"));
const About = lazy(() => import("./src/Components/About"));
const RestaurantMenu = lazy(() => import("./src/Components/RestaurantMenu"));
const AppLayout = () => {
const [user, setUser] = useState({
name: "Mohd Amaan",
email: "[email protected]",
});
return (
<Provider store={store}>
<UserContext.Provider
value={{
user: user,
setUser: setUser,
}}
>
<Header />
<Outlet />
<Footer />
</UserContext.Provider>
</Provider>
);
};
const appRouter = createBrowserRouter([
{
path: "/",
element: <AppLayout />,
errorElement: <Error />,
children: [
{
path: "/",
element: <Body />,
},
{
path: "/about",
element: (
<Suspense fallback={<ShimmerAbout />}>
<About />
</Suspense>
),
},
{
path: "/contact",
element: <Contact />,
},
{
path: "/restaurant/:resId",
element: (
<Suspense fallback={<ShimmerMenu />}>
<RestaurantMenu />
</Suspense>
),
},
{
path: "/instamart",
element: (
<Suspense fallback={<ShimmerInstamart />}>
<Instamart />
</Suspense>
),
},
{
path: "/help",
element: <Help />,
},
{
path: "/cart",
element: <Cart />,
},
{
path: "/login",
element: <LogIn />,
},
],
},
]);
const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(<RouterProvider router={appRouter} />);