Cart Cost
The component renders a Money component with the cost associated with the prop.
If no prop is specified, then it defaults to .
Depends on and must be a child of
Anchor to propsProps
- Anchor to amountTypeamountTypeamountType'total' | 'subtotal' | 'tax' | 'duty''total' | 'subtotal' | 'tax' | 'duty'
A string type that defines the type of cost needed. Valid values:
total,subtotal,tax, orduty.- Anchor to asasasComponentGenericComponentGeneric
An HTML tag or React Component to be rendered as the base element wrapper. The default is
div.- Anchor to childrenchildrenchildrenReact.ReactNodeReact.ReactNode
Any
elements.- Anchor to measurementmeasurementmeasurementPartialDeep<UnitPriceMeasurement, {recurseIntoArrays: true}>PartialDeep<UnitPriceMeasurement, {recurseIntoArrays: true}>
- Anchor to measurementSeparatormeasurementSeparatormeasurementSeparatorReactNodeReactNode
Customizes the separator between the money output and the measurement output. Used with the
measurementprop. Defaults to'/'.- Anchor to withoutCurrencywithoutCurrencywithoutCurrencybooleanboolean
Whether to remove the currency symbol from the output.
- Anchor to withoutTrailingZeroswithoutTrailingZeroswithoutTrailingZerosbooleanboolean
Whether to remove trailing zeros (fractional money) from the output.
Examples
import {CartCost} from '@shopify/hydrogen-react';
export default function CartTotals() {
return (
<>
<div>
Subtotal: <CartCost amountType="subtotal" />
</div>
<div>
Tax: <CartCost amountType="tax" />
</div>
<div>
Total: <CartCost />
</div>
</>
);
}
Examples
Example code
Description
I am the default example
JavaScript
import {CartCost} from '@shopify/hydrogen-react'; export default function CartTotals() { return ( <> <div> Subtotal: <CartCost amountType="subtotal" /> </div> <div> Tax: <CartCost amountType="tax" /> </div> <div> Total: <CartCost /> </div> </> ); }TypeScript
import {CartCost} from '@shopify/hydrogen-react'; export default function CartTotals() { return ( <> <div> Subtotal: <CartCost amountType="subtotal" /> </div> <div> Tax: <CartCost amountType="tax" /> </div> <div> Total: <CartCost /> </div> </> ); }
Was this page helpful?