Cart Costcomponent
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 amountTypeamountType"total" | "subtotal" | "tax" | "duty"
A string type that defines the type of cost needed. Valid values:
total
,subtotal
,tax
, orduty
.- Anchor to childrenchildrenReact.ReactNode
Any
elements.
- ComponentGeneric
An HTML tag or React Component to be rendered as the base element wrapper. The default is
div
.- Anchor to withoutCurrencywithoutCurrencyboolean
Whether to remove the currency symbol from the output.
- Anchor to withoutTrailingZeroswithoutTrailingZerosboolean
Whether to remove trailing zeros (fractional money) from the output.
- Anchor to measurementmeasurementPartialDeep<UnitPriceMeasurement, {recurseIntoArrays: true}>
- Anchor to measurementSeparatormeasurementSeparatorReactNode
Customizes the separator between the money output and the measurement output. Used with the
measurement
prop. Defaults to'/'
.
CartCostPropsForDocs
- amountType
A string type that defines the type of cost needed. Valid values: `total`, `subtotal`, `tax`, or `duty`.
"total" | "subtotal" | "tax" | "duty"
- children
Any `ReactNode` elements.
React.ReactNode
- as
An HTML tag or React Component to be rendered as the base element wrapper. The default is `div`.
ComponentGeneric
- withoutCurrency
Whether to remove the currency symbol from the output.
boolean
- withoutTrailingZeros
Whether to remove trailing zeros (fractional money) from the output.
boolean
- measurement
A [UnitPriceMeasurement object](https://shopify.dev/api/storefront/2024-01/objects/unitpricemeasurement).
PartialDeep<UnitPriceMeasurement, {recurseIntoArrays: true}>
- measurementSeparator
Customizes the separator between the money output and the measurement output. Used with the `measurement` prop. Defaults to `'/'`.
ReactNode
export interface CartCostPropsForDocs<AsType extends React.ElementType = 'div'>
extends Omit<MoneyPropsBase<AsType>, 'data'>,
CartCostPropsBase {}
Example code
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> </> ); }