Skip to main content

useCartLine

The useCartLine hook provides access to the CartLine object from the Storefront API. It must be a descendent of a CartProvider component.

The useCartLine hook provides access to the CartLine object from the Storefront API. It must be a descendent of a CartProvider component.

Examples
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>;
}


Was this page helpful?