hydrogen/packages/hydrogen/src/hooks/useCartLinesUpdateCallback/README.md
2021-11-09 18:20:09 -08:00

1.3 KiB

The useCartLinesUpdateCallback hook returns a callback that can be used to update lines in a cart. It must be a descendent of a CartProvider component.

Example code

import {useCartLinesUpdateCallback} from '@shopify/hydrogen';

export function CustomAdjustQuantityButton({lineId, newQuantity}) {
  const updateLines = useCartLinesUpdateCallback();

  return (
    <button
      onClick={() => {
        updateLines([
          {
            id: lineId,
            quantity: newQuantity,
          },
        ]);
      }}
    >
      +
    </button>
  );
}

Return value

A callback to update lines in a cart. The callback expects one argument that corresponds to the input you would provide to the Storefront API's cartLinesUpdate mutation.