Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
14 views1 page

Subtotal Js

The document is a React component named Subtotal that displays the total price of items in a shopping basket. It uses CurrencyFormat to format the total and includes a checkbox for gift options. The component also has a button that navigates to the payment page when clicked.

Uploaded by

chinmayikiran6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views1 page

Subtotal Js

The document is a React component named Subtotal that displays the total price of items in a shopping basket. It uses CurrencyFormat to format the total and includes a checkbox for gift options. The component also has a button that navigates to the payment page when clicked.

Uploaded by

chinmayikiran6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Subtotal.

js

import React from "react"; import "./Subtotal.css";


import CurrencyFormat from "react-currency-format"; import { useStateValue } from
"./StateProvider"; import { getBasketTotal } from "./reducer";
import { useHistory } from "react-router-dom";

function Subtotal() { const history = useHistory();


const [{ basket }, dispatch] = useStateValue();

return (
<div className="subtotal">
<CurrencyFormat renderText={(value) => (
<>
<p>
{/* Part of the homework */}
Subtotal ({basket.length} items): <strong>{value}</strong>
</p>
<small className="subtotal gift">
<input type="checkbox" /> This order contains a gift
</small>
</>
)}
decimalScale={2} value={getBasketTotal(basket)} // Part of the homework
displayType={"text"} thousandSeparator={true} prefix={"$"}
/>

<button onClick={e => history.push('/payment')}>Proceed to Checkout</button>


</div>
);
}

export default Sub

You might also like