-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.jsx
50 lines (39 loc) · 1.02 KB
/
App.jsx
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
import { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import Navbar from './components/Navbar';
import CartContainer from './components/CartContainer';
import { calculateTotals, getCartItems } from './features/cart/cartSlice';
import Modal from './components/Modal';
function App() {
const { cartItems, isLoading, isError } = useSelector((state) => state.cart);
const { isOpen } = useSelector((state) => state.modal);
const dispatch = useDispatch();
useEffect(() => {
dispatch(getCartItems('hello world'));
}, [dispatch]);
useEffect(() => {
dispatch(calculateTotals());
}, [cartItems, dispatch]);
if (isLoading) {
return (
<div className="loading">
<h1>loading...</h1>
</div>
);
}
if (isError) {
return (
<div className="loading">
<h1>Oops, something went wrong!</h1>
</div>
);
}
return (
<main>
<Navbar />
<CartContainer />
{isOpen && <Modal />}
</main>
);
}
export default App;