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

@nordcom/commerce-cart
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.

CartDevtools CartFormProps CartProviderProps AppCartConfig BaseCartActions BuyerIdentityActions CartActions CartAttributeActions

Metadata@nordcom/commerce-cart@0.2.2Open in GitHub ↗

On this page