Skip to main content
Order history, pagination, detail, tracking and status buckets for the signed-in customer. Every hook is gated on a customer access token: while signed out it returns empty data and never fetches.

Listing

useOrders(options?)

Parameterless, it keeps the original flat-list contract:
Pass any option to switch to the paged form — the same call returns pageInfo and the options are forwarded to the Storefront connection:
Paged and flat calls use separate cache entries. A screen that shows the legacy list keeps its cache when another screen paginates.

useInfiniteOrders({ first?, sortBy? })

Cursor-paginated list with an automatic fetchNextPage (TanStack useInfiniteQuery); pages are flattened into one orders array.
sortBy accepts 'newest' | 'oldest' | 'highest-value' | 'lowest-value'. The Storefront only exposes PROCESSED_AT and TOTAL_PRICE plus reverse, which is exactly what these tokens map onto.

useOrderHistory({ sortBy?, first? })

A one-page listing with an explicit onLoadMore() and hasNextPage — useful when you render your own “Load more” button instead of infinite scroll.

Status buckets

All three read the same cached page as useOrders() (one network request, three views) and filter client-side:
The predicates and filters are pure and exported under the orders/* modules (isPendingOrder, isCompletedOrder, isCancelledOrder, filterOrders), so you can bucket any order list you already hold without a hook.

Detail

useOrder(orderId)

Storefront API 2026-07 has no standalone order-by-id query, and node(id:) requires a customer-token header our client does not send. The hook therefore resolves an order the honest way:
  1. look in the order caches already populated by the lists above (the common path — the user tapped an order that is already loaded);
  2. on a miss, fetch one page of 50 and match by id;
  3. if it is still missing, notFound is true. An order beyond the synced pages is not addressable by id in Storefront — this is a documented gap, not a hidden error.

useOrderTracking(orderId)

Status, tracking numbers/URLs and a derived timeline for one order:
  • status — cancelled | fulfilled | in-progress | partial | unfulfilled | pending | scheduled | on-hold | restocked. Derived from canceledAt / financialStatus / fulfillmentStatus; cancelled always wins.
  • tracking — { company, numbers: string[], urls: string[] }[], one entry per successful fulfillment that carries tracking.
  • timeline — only the steps Shopify exposes: ordered, one shipped step per fulfillment, cancelled. The Storefront API does not expose fulfillment dates, so shipped steps carry the company, not a timestamp.
  • statusUrl — Shopify’s official order-status page (open it in a browser or web view for the full timeline).
The derivation functions are pure and exported for custom UI: deriveOrderStatus, extractTrackingInfo, deriveOrderTimeline, hasShipment.

usePrefetchOrders()

Warm the infinite list (and therefore useOrder’s cache) at tap intent:

Order shape

Every node includes:
  • id, name, orderNumber, processedAt, statusUrl
  • financialStatus (PAID, PENDING, REFUNDED, …)
  • fulfillmentStatus (FULFILLED, UNFULFILLED, …)
  • canceledAt
  • currencyCode, subtotalPrice, totalPrice, currentTotalPrice — { amount, currencyCode }
  • lineItems(first: 50) — title, quantity, currentQuantity, discountedTotalPrice, originalTotalPrice, and variant (id, title, price, image)
  • successfulFulfillments — trackingCompany and trackingInfo (number, url)

Service API

Both throw 'Not authenticated' when no access token is set. getOrdersPage additionally renews a near-expiry token before reading.