AddToCartButton
The AddToCartButton
component renders a button that adds an item to the cart when pressed.
It must be a descendent of the CartProvider
component.
Example code
Anchor link to section titled "Example code"
Name | Type | Description |
---|---|---|
attributes? | Object< |
An array of cart line attributes that belong to the item being added to the cart. |
sellingPlanId? | string |
The selling plan ID of the subscription product variant. A selling plan represents how a product can be sold and purchased. |
variantId? | string | null |
The ID of the variant. |
quantity? | number |
The item quantity. |
children | ReactNode |
Any ReactNode elements. |
accessibleAddingToCartLabel? | string |
The text that's announced by the screen reader when the item is being added to the cart. Used for accessibility purposes only and not displayed on the page. |
onClick? | (event?: React.MouseEvent< |
A click event handler. Default behaviour triggers the click event, unless prevented. |
buttonRef? | Ref< |
A reference to the underlying button. |
as? | React.ElementType with button as default |
Provides a React element or component to render as the underlying button. For accessibility compliance, use either a button element or a component that renders an underlying button. |
Component type
Anchor link to section titled "Component type"The AddToCartButton
component is a client component, which means that it renders on the client. For more information about component types, refer to React Server Components.