use Cart Linecomponent
component
The hook provides access to the CartLine object from the Storefront API. It must be a descendent of a
component.
Anchor to useCartLineuse Cart Line()
use Cart Line()
must be a descendent of a
component.
CartLinePartialDeep
PartialDeep<
CartLine | ComponentizableCartLine,
{recurseIntoArrays: true}
>
Was this section helpful?
Example code
import {CartLineProvider, useCartLine} from '@shopify/hydrogen-react';
export function CartWrapper({cart}) {
const firstCartLine = cart.lines.nodes[0];
return (
<CartLineProvider line={firstCartLine}>
<CartLineQuantity />
</CartLineProvider>
);
}
function CartLineQuantity() {
const cartLine = useCartLine();
return <div>{cartLine.quantity}</div>;
}