useQuery or useMutation from @tanstack/react-query v5. The QueryClient is configured with a global staleTime of 5 minutes for most data, with tighter windows for frequently-changing data.
staleTime configuration
| Hook category | staleTime |
|---|---|
| Products (inventory) | 2 minutes (PRODUCTS_STALE_TIME) |
| Product detail | 1 minute (PRODUCT_DETAIL_STALE_TIME) |
| Orders | 2 minutes (ORDERS_STALE_TIME) |
| Order detail | 1 minute (ORDER_DETAIL_STALE_TIME) |
| Points balance | 5 minutes (POINTS_STALE_TIME) |
Product hooks
Defined insrc/hooks/useProducts.ts.
useProducts()
['products', options?.section, options?.categoryId, options?.limit]
Fetches storefront products with optional filters. Uses keepPreviousData to avoid flash during option changes.
useFeaturedProducts()
['products', 'featured', section]
useNewProducts()
['products', 'new', section]
useBestsellerProducts()
['products', 'bestseller', options?.section, options?.limit]
useRecentProducts()
['products', 'recent', limit]Returns products added within the last 14 days.
useDiscountedProducts()
['products', 'discounted', limit]
useProductBySlug()
['products', 'detail', section, slug]Only fires when both
slug and section are truthy (enabled: !!slug && !!section). Uses the tighter 1-minute staleTime.
Order hooks
Defined insrc/hooks/useOrders.ts.
useCustomerOrders()
['orders', customerId]Only fires when
customerId is defined (enabled: !!customerId).
useOrder()
['orders', 'detail', orderId]Fetches a single order. Disabled when
orderId is undefined.
useCreateOrder()
Mutation hook. On success, invalidates three query keys:['orders', variables.customer_id]— refreshes order list['loyalty', 'balance', variables.customer_id]— refreshes points balance['loyalty', 'tier', variables.customer_id]— refreshes tier status
usePointsBalance()
['points', customerId]Calls
getPointsBalance() which uses the get_customer_points_balance Supabase RPC.
useOrderTracking()
Mutation hook that callsgetTrackingInfo(trackingNumber) to look up shipment status.
Auth hook
Defined insrc/hooks/useAuth.ts.
useAuth()
AuthContext. Must be called inside <AuthProvider>. Throws an error if used outside the provider tree.
Search hook
useSearch()
Implements debouncing internally so search queries are not fired on every keystroke. Wraps
searchProducts() from search.service.ts, which searches name, short_description, description, sku, and tags.
Additional hooks
useAppMonitoring()
useCategories() / useCategoriesBySection()
['categories', section]
useCoupons()
Query key:['coupons']
useLoyalty()
Query key:['loyalty'] — fetches tier info, history, and redemption options.
useStoreSettings()
Query key:['store-settings']
useStats()
Query key:['stats'] — user-level purchase statistics.
useAddresses()
Query key:['addresses'] — current user’s saved addresses.
Complete hook reference
| Hook | Query Key | Service |
|---|---|---|
useProducts(options?) | ['products', section, categoryId, limit] | products.service |
useFeaturedProducts(section?) | ['products', 'featured', section] | products.service |
useNewProducts(section?) | ['products', 'new', section] | products.service |
useBestsellerProducts(options?) | ['products', 'bestseller', section, limit] | products.service |
useRecentProducts(limit?) | ['products', 'recent', limit] | products.service |
useDiscountedProducts(limit?) | ['products', 'discounted', limit] | products.service |
useProductBySlug(slug, section) | ['products', 'detail', section, slug] | products.service |
useCustomerOrders(customerId?) | ['orders', customerId] | orders.service |
useOrder(orderId?) | ['orders', 'detail', orderId] | orders.service |
useCreateOrder() | mutation → invalidates ['orders'], ['loyalty'] | orders.service |
usePointsBalance(customerId?) | ['points', customerId] | loyalty.service (RPC) |
useOrderTracking() | mutation | orders.service |
useCategories(section?) | ['categories', section] | categories.service |
useSearch(query) | debounced | search.service |
useAuth() | — (context) | AuthContext |
useAddresses() | ['addresses'] | addresses.service |
useCoupons() | ['coupons'] | coupons.service |
useLoyalty() | ['loyalty'] | loyalty.service |
useStoreSettings() | ['store-settings'] | settings.service |
useStats() | ['stats'] | stats.service |
useDebounce(value, delay) | — | Generic utility |
useHaptic() | — | Navigator.vibrate API |
useNotification() | — | notifications.store |
useAppMonitoring() | — | Sentry init |
