Skip to content

Commit

Permalink
カート状態が変化するたびに発火する仕組みを構築しよう
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yoshiii committed Sep 19, 2022
1 parent e95c069 commit ebc1918
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions src/App.tsx
@@ -1,10 +1,17 @@
import { useState } from "react";
import { useEffect } from "react";
import { useDispatch } from "react-redux";
import cartItems from "./cartItems";
import CartContainer from "./components/CartContainer";
import Navbar from "./components/Navbar";
import { calculateTotals } from "./features/cart/CartSlice";
import { useAppSelector } from "./store";

function App() {
const [count, setCount] = useState(0);

const dispatch = useDispatch();
const { cartItems } = useAppSelector((store) => store.cart);
useEffect(() => {
dispatch(calculateTotals());
}, [cartItems]);
return (
<div className="App">
<Navbar />
Expand Down
2 changes: 1 addition & 1 deletion src/components/CartContainer.tsx
Expand Up @@ -42,7 +42,7 @@ const CartContainer = () => {
</Stack>
<Divider sx={{ my: 7 }} />
<Box sx={{ textAlign: "right" }}>
<Typography variant="h3">合計:{total}</Typography>
<Typography variant="h3">合計:{total.toLocaleString()}</Typography>
</Box>
<Box mt={4} sx={{ textAlign: "center" }}>
<Button
Expand Down

0 comments on commit ebc1918

Please sign in to comment.