-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.js
92 lines (86 loc) · 2.29 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
import React, { lazy, Suspense, useState } from "react";
import ReactDOM from "react-dom/client";
import Navbar from "./src/components/Navbar";
import Body from "./src/components/Body";
import Footer from "./src/components/Footer";
import Error from "./src/components/Error";
import RestaurantMenu from "./src/components/RestaurantMenu";
import { createBrowserRouter, RouterProvider, Outlet } from "react-router-dom";
import Shimmer from "./src/components/Shimmer";
import useIsOnline from "./src/utils/useIsOnline";
import OfflineMessage from "./src/components/OfflineMessage";
import UserContext from "./src/utils/UserContext";
const About = lazy(() => import("./src/components/About"));
const Profile = lazy(() => import("./src/components/Profile"));
const Cart = lazy(() => import("./src/components/Cart"));
import { Provider } from "react-redux";
import store from "./src/utils/store";
const App = () => {
const online = useIsOnline();
const [user, setUser] = useState({
name: "yoda",
});
return (
<Provider store={store}>
<UserContext.Provider
value={{
user:user,
setUser:setUser
}}
>
<Navbar />
{navigator.geolocation ? (
<Outlet />
) : (
<div>Please enable location services</div>
)}
<Footer />
<OfflineMessage online={online} />
</UserContext.Provider>
</Provider>
);
};
const router = createBrowserRouter([
{
path: "/",
element: <App />,
errorElement: <Error />,
children: [
{
path: "/",
element: <Body />,
},
{
path: "/cart",
element: (
<Suspense fallback={<Shimmer />}>
<Cart />
</Suspense>
),
},
{
path: "/about",
element: (
<Suspense fallback={<Shimmer />}>
<About />
</Suspense>
),
},
{
path: "/profile",
element: (
<Suspense fallback={<Shimmer />}>
<Profile />
</Suspense>
),
},
{
path: "/restaurant/:id",
element: <RestaurantMenu />,
},
],
},
]);
const root = ReactDOM.createRoot(document.getElementById("root"));
// root.render(container);
root.render(<RouterProvider router={router} />);