doc: add useStateValue and getBasketTotal

This commit is contained in:
Leon Xu committed 2022-05-05 21:38:18 -07:00
1 parent d64671d0f5
commit 7c6ee1d588
1 file changed
+5 -2
+5 -2
View File
@@ -1,15 +1,18 @@
import React from "react"; import React from "react";
import CurrencyFormat from "react-currency-format"; import CurrencyFormat from "react-currency-format";
import { useStateValue } from "../redux/StateProvider";
import { getBasketTotal } from "../redux/reducer";
import "./Subtotal.css"; import "./Subtotal.css";
function Subtotal() { function Subtotal() {
const [{ basket }, dispatch] = useStateValue();
return ( return (
<section className="subtotal"> <section className="subtotal">
<CurrencyFormat <CurrencyFormat
renderText={(value) => ( renderText={(value) => (
<> <>
<p> <p>
Subtotal (0 items): <strong>0</strong> Subtotal ({basket.length} items): <strong>{value}</strong>
</p> </p>
<small className="subtotal__gift"> <small className="subtotal__gift">
<input type="checkbox" /> This order contains a gift <input type="checkbox" /> This order contains a gift
@@ -17,7 +20,7 @@ function Subtotal() {
</> </>
)} )}
decimalScale={2} decimalScale={2}
value={0} value={getBasketTotal(basket)}
displayType={"text"} displayType={"text"}
thousandSeparator={true} thousandSeparator={true}
prefix={"$"} prefix={"$"}