Skip to content

feature-cart

@evolve-storefront/feature-cart · v1.1.0 · Storybook ↗

The cart and checkout: line items, totals, discount codes, the header badge and add-to-cart. The package ships the data hooks and ready-made parts; your app composes the pages.

Get started

  1. Install the package with the peer dependencies it needs. It comes from the Evolve registry, which needs a one-time sign-in.

    pnpm add @evolve-storefront/feature-cart @labdigital/graphql-fetcher @tanstack/react-query graphql next next-intl react
    Requirements6
    @labdigital/graphql-fetcher>=3
    @tanstack/react-query>=5
    graphql>=16
    next>=16.2.11 <17
    next-intl>=4
    react>=19
  2. Import its styles in the stylesheet where you load Tailwind. Without them the components render unstyled.

    @import "@evolve-storefront/feature-cart/styles.css";
  3. Wrap your app in CartProvider. Setup lists its props.

  4. Add its translations to your message files with evolve messages.

Then render it on a page:

import { CartProvider } from "@evolve-storefront/feature-cart/provider";
import { useCart } from "@evolve-storefront/feature-cart/hooks";
import { Cart, CartEmpty, CartSkeleton } from "@evolve-storefront/feature-cart/cart";
<CartProvider hasSession={hasSession} businessUnitId={businessUnitId}>
<CartPage />
</CartProvider>;
function CartPage() {
const { data: cart, isPending } = useCart();
// Gate on isPending, never isLoading — the cart query is auth-gated, and
// `isLoading` is `isPending && isFetching`, so it reports false while gated.
if (isPending) return <CartSkeleton lines={badgeCount} />;
if (!cart || cart.lineItems.length === 0) return <CartEmpty />;
return <Cart cart={cart} />;
}

Components

What you place on your pages. Each one has a preview, its props, and how to change its layout.

Hooks

62 hooks to read and change the data yourself, for when you build your own UI. The example above only needs useCart. All hooks

Engine support

More in this package

  • Setup and server: what the package needs in your project.
  • Advanced: contexts, graphql documents, data and cache helpers, errors, schemas, other functions and constants, types.