Skip to main content

Core Concepts

Architecture

The SDK operates as a headless-first layer between your React Native app and two Shopify APIs:
  • Stackfront REST API — managed services (loyalty, reviews, stories, push notifications, events, billing, config). Handled by the ApiClient service.
  • Shopify Storefront GraphQL API — commerce primitives (products, cart, checkout, customer, orders). Handled by the StorefrontClient service.
The SDK abstracts this so your code never needs to know which API is being called.

Provider & Context

Wrap your root component in StackfrontProvider. On mount, it fetches remote config, initializes all services, and exposes them via React context. All hooks and services access this context through the useStackfront() hook:
import { useStackfront } from 'react-native-stackfront-sdk';

function MyComponent() {
  const { ready, config, products, cart, events } = useStackfront();

  if (!ready) return <Loading />;
  // ...
}

Services vs Hooks

The SDK provides two layers of API: Services — direct imperative access to underlying functionality (API calls, storage, GraphQL queries). Accessible via useStackfront(). Hooks — opinionated React wrappers over services with built-in state management (data, loading, error). Prefer hooks for most UI work.
LayerExampleWhen to use
useStackfront().productsService — raw API callsComposing custom logic
useProducts()Hook — reactive stateStandard UI rendering

Available Hooks (25)

HookReturnsDescription
useStackfront()Context valueAccess every service, config, and lifecycle state
useProducts()Product[]Paginated product listing
useProduct(handle)Product | nullSingle product by handle
useSearch(query)Product[]Full-text product search
useCollections()Collection[]Collection listing
useCart()Cart | nullCurrent cart with line mutations
useCheckout(){ url, loading }Checkout URL for web checkout
useCustomer()Customer | nullLogged-in customer profile
useOrders()Order[]Customer order history
usePush(){ permission, token }Push notification registration state
useConfig()SdkConfigResponseRemote SDK configuration
useFeatureFlags()FeatureFlag[]Remote feature flags
useBranding()BrandingConfigStore branding settings
useBanners()Banner[]Active banners
useAnnouncements()Announcement[]Announcement bar config
usePopups()Popup[]Popup/overlay config
useStories()Story[]Story/collection highlights
useReviews()Review[]Product reviews
useSocialProof()SocialProof[]Live social proof notifications
useWishlist()WishlistItem[]User’s wishlist
useLoyalty()LoyaltyDataPoints, tiers, and rewards
useBilling()BillingStatusApp subscription/billing info
useIntegrations()Integration[]Third-party integration status
useAbandonedCart(){ enabled, optedIn, optIn, optOut }Abandoned cart notification opt-in state and controls

Available Services (15)

ServiceDescription
ApiClientHTTP client for the Stackfront REST API
StorefrontClientGraphQL client for the Shopify Storefront API
StorageServiceAsyncStorage wrapper for local persistence
EventServiceEvent tracking and batching pipeline
DeviceServicePush notification device registration
ConfigServiceRemote config fetching
ProductServiceProduct and collection GraphQL queries
CartServiceCart CRUD via Storefront GraphQL mutations
CustomerServiceCustomer auth, profile, and orders
LoyaltyServicePoints, tiers, and rewards API
ReviewServiceProduct review API
StoryServiceStory management API
SocialProofServiceLive social proof feed API
IntegrationServiceThird-party integration data API
BillingServiceApp subscription billing API
WishlistServiceLocal wishlist persistence

GraphQL Operations

The SDK bundles pre-written GraphQL queries and mutations for the Shopify Storefront API. These are used internally by the ProductService, CartService, and CustomerService, and are also exported directly:
import { GET_PRODUCTS, CART_CREATE, CUSTOMER_GET } from 'react-native-stackfront-sdk';
Available operations:
OperationTypeDescription
GET_PRODUCTSQueryPaginated product list
GET_PRODUCTQuerySingle product by handle
GET_PRODUCT_BY_IDQuerySingle product by ID
GET_COLLECTIONSQueryPaginated collection list
GET_COLLECTIONQuerySingle collection with products
SEARCH_PRODUCTSQueryFull-text product search
CART_CREATEMutationCreate a new cart
CART_GETQueryFetch cart by ID
CART_LINES_ADDMutationAdd lines to cart
CART_LINES_UPDATEMutationUpdate cart line quantities
CART_LINES_REMOVEMutationRemove lines from cart
CART_BUYER_IDENTITY_UPDATEMutationSet customer identity on cart
CUSTOMER_CREATEMutationRegister a new customer
CUSTOMER_ACCESS_TOKEN_CREATEMutationLog in (create access token)
CUSTOMER_ACCESS_TOKEN_DELETEMutationLog out (delete access token)
CUSTOMER_GETQueryFetch customer profile + orders
CUSTOMER_RECOVERMutationPassword reset email
CUSTOMER_UPDATEMutationUpdate customer profile

Lifecycle

  1. App starts → StackfrontProvider mounts
  2. Config fetched from Stackfront API (storefront token, OneSignal ID, feature flags)
  3. Storefront GraphQL client initialized
  4. Storage initialized (AsyncStorage)
  5. OneSignal initialized if configured
  6. ready = true
  7. app_opened event tracked
  8. App renders
Access ready and error from useStackfront() to gate your UI:
const { ready, error } = useStackfront();
if (error) return <ErrorScreen error={error} />;
if (!ready) return <SplashScreen />;
return <AppContent />;