useMaybeCart
●cart · /react·function
Variant of that returns null when no provider is mounted.
Useful for components rendered both inside and outside the cart tree (e.g.,
shared header components on auth-only routes).
Signature
function useMaybeCart(): { cart: { attributes: { key: string; value: string }[]; buyerIdentity: BuyerIdentity; checkoutUrl: string; cost: CartCostValue; discountCodes: { applicable: boolean; code: string }[]; giftCards: { amountLeft: Money; id: string; lastCharacters: string }[]; id: string; lines: CartLine<unknown>[]; note: string; totalQuantity: number }; cartReady: boolean; error: string; status: CartStatus; addLine: unknown; clear: unknown; removeLine: unknown; updateLine: unknown };Returns
The same shape as , or null when no provider is
present.
Related
CartDevtools CartFormProps CartProviderProps AppCartConfig BaseCartActions BuyerIdentityActions CartActions CartAttributeActions