@shopify/hydrogen-react
Version:
React components, hooks, and utilities for creating custom Shopify storefronts
62 lines (61 loc) • 6.33 kB
TypeScript
import { CartBuyerIdentityInput, CountryCode, Cart as CartType } from './storefront-api-types.js';
import { CartWithActions } from './cart-types.js';
import { PartialDeep } from 'type-fest';
export declare const CartContext: import("react").Context<CartWithActions | null>;
/**
* The `useCart` hook provides access to the cart object. It must be a descendent of a `CartProvider` component.
*/
export declare function useCart(): CartWithActions;
export declare function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLineRemove, onLineUpdate, onNoteUpdate, onBuyerIdentityUpdate, onAttributesUpdate, onDiscountCodesUpdate, onCreateComplete, onLineAddComplete, onLineRemoveComplete, onLineUpdateComplete, onNoteUpdateComplete, onBuyerIdentityUpdateComplete, onAttributesUpdateComplete, onDiscountCodesUpdateComplete, data: cart, cartFragment, customerAccessToken, countryCode, }: {
/** Any `ReactNode` elements. */
children: React.ReactNode;
/** Maximum number of cart lines to fetch. Defaults to 250 cart lines. */
numCartLines?: number;
/** A callback that is invoked when the process to create a cart begins, but before the cart is created in the Storefront API. */
onCreate?: () => void;
/** A callback that is invoked when the process to add a line item to the cart begins, but before the line item is added to the Storefront API. */
onLineAdd?: () => void;
/** A callback that is invoked when the process to remove a line item to the cart begins, but before the line item is removed from the Storefront API. */
onLineRemove?: () => void;
/** A callback that is invoked when the process to update a line item in the cart begins, but before the line item is updated in the Storefront API. */
onLineUpdate?: () => void;
/** A callback that is invoked when the process to add or update a note in the cart begins, but before the note is added or updated in the Storefront API. */
onNoteUpdate?: () => void;
/** A callback that is invoked when the process to update the buyer identity begins, but before the buyer identity is updated in the Storefront API. */
onBuyerIdentityUpdate?: () => void;
/** A callback that is invoked when the process to update the cart attributes begins, but before the attributes are updated in the Storefront API. */
onAttributesUpdate?: () => void;
/** A callback that is invoked when the process to update the cart discount codes begins, but before the discount codes are updated in the Storefront API. */
onDiscountCodesUpdate?: () => void;
/** A callback that is invoked when the process to create a cart completes */
onCreateComplete?: () => void;
/** A callback that is invoked when the process to add a line item to the cart completes */
onLineAddComplete?: () => void;
/** A callback that is invoked when the process to remove a line item to the cart completes */
onLineRemoveComplete?: () => void;
/** A callback that is invoked when the process to update a line item in the cart completes */
onLineUpdateComplete?: () => void;
/** A callback that is invoked when the process to add or update a note in the cart completes */
onNoteUpdateComplete?: () => void;
/** A callback that is invoked when the process to update the buyer identity completes */
onBuyerIdentityUpdateComplete?: () => void;
/** A callback that is invoked when the process to update the cart attributes completes */
onAttributesUpdateComplete?: () => void;
/** A callback that is invoked when the process to update the cart discount codes completes */
onDiscountCodesUpdateComplete?: () => void;
/** An object with fields that correspond to the Storefront API's [Cart object](https://shopify.dev/api/storefront/latest/objects/cart). */
data?: PartialDeep<CartType, {
recurseIntoArrays: true;
}>;
/** A fragment used to query the Storefront API's [Cart object](https://shopify.dev/api/storefront/latest/objects/cart) for all queries and mutations. A default value is used if no argument is provided. */
cartFragment?: string;
/** A customer access token that's accessible on the server if there's a customer login. */
customerAccessToken?: CartBuyerIdentityInput['customerAccessToken'];
/** The ISO country code for i18n. */
countryCode?: CountryCode;
}): JSX.Element;
/** Check for storage availability funciton obtained from
* https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API
*/
export declare function storageAvailable(type: 'localStorage' | 'sessionStorage'): boolean | undefined;
export declare const defaultCartFragment = "\nfragment CartFragment on Cart {\n id\n checkoutUrl\n totalQuantity\n buyerIdentity {\n countryCode\n customer {\n id\n email\n firstName\n lastName\n displayName\n }\n email\n phone\n }\n lines(first: $numCartLines) {\n edges {\n node {\n id\n quantity\n attributes {\n key\n value\n }\n cost {\n totalAmount {\n amount\n currencyCode\n }\n compareAtAmountPerQuantity {\n amount\n currencyCode\n }\n }\n merchandise {\n ... on ProductVariant {\n id\n availableForSale\n compareAtPriceV2 {\n ...MoneyFragment\n }\n priceV2 {\n ...MoneyFragment\n }\n requiresShipping\n title\n image {\n ...ImageFragment\n }\n product {\n handle\n title\n }\n selectedOptions {\n name\n value\n }\n }\n }\n }\n }\n }\n cost {\n subtotalAmount {\n ...MoneyFragment\n }\n totalAmount {\n ...MoneyFragment\n }\n totalDutyAmount {\n ...MoneyFragment\n }\n totalTaxAmount {\n ...MoneyFragment\n }\n }\n note\n attributes {\n key\n value\n }\n discountCodes {\n code\n }\n}\n\nfragment MoneyFragment on MoneyV2 {\n currencyCode\n amount\n}\nfragment ImageFragment on Image {\n id\n url\n altText\n width\n height\n}\n";