Official React Native SDK for the CoCart REST API. Build headless WooCommerce storefronts in React Native using simple hooks.
Note
This SDK is a thin wrapper over @cocartheadless/sdk. It does not provide pre-built UI screens or native components — it provides state and data via hooks that you wire into your own screens using standard React Native primitives.
Important
This SDK is still in development and not yet ready for production use. Provide feedback if you experience a bug.
- Add SDK docs to documentation site
- Add support for Cart API extras
- Add Checkout API support
It adds three things on top of the core SDK:
- Storage adapters —
MMKVStorageandAsyncStorageAdapterso cart sessions and tokens persist across app restarts CoCartProvider— constructs the client, restores the session on mount and on app foreground- Hooks —
useCart,useCartMutations,useProducts,useAccountfor idiomatic React Native usage
All core logic (authentication, cart, products, sessions, JWT, 2FA, account, error handling) is inherited from the TypeScript SDK automatically.
- React Native 0.72+ or Expo SDK 50+
- React 18+
- CoCart plugin installed on your WooCommerce store
@cocartheadless/sdk^1.0.0 (peer dependency)- CoCart JWT Authentication plugin (optional, for JWT auth)
See SUPPORT.md for our versioning policy and support lifecycle.
npm install @cocart/react-native-sdk @cocartheadless/sdkFor persistent cart sessions (recommended):
MMKV (fast synchronous storage — requires native build):
npm install react-native-mmkv
cd ios && pod installAsyncStorage (async, Expo managed workflow compatible):
npm install @react-native-async-storage/async-storageIf neither is installed, sessions are kept in memory only and lost on app restart.
Wrap your app in CoCartProvider, then use hooks in any component:
import React from 'react';
import { CoCartProvider, MMKVStorage } from '@cocart/react-native-sdk';
import { StorefrontScreen } from './screens/StorefrontScreen';
export default function App() {
return (
<CoCartProvider
siteURL="https://your-store.com"
options={{ storage: new MMKVStorage() }}
>
<StorefrontScreen />
</CoCartProvider>
);
}import React from 'react';
import { View, Text, Button, FlatList } from 'react-native';
import { useCart, useCartMutations, useProducts } from '@cocart/react-native-sdk';
export function StorefrontScreen() {
const { products, loading: productsLoading } = useProducts();
const { cart, loading: cartLoading } = useCart();
const { addItem } = useCartMutations();
if (productsLoading || cartLoading) return <Text>Loading...</Text>;
return (
<View>
<FlatList
data={products?.toObject() as any[]}
keyExtractor={(item) => String(item.id)}
renderItem={({ item }) => (
<View>
<Text>{item.name}</Text>
<Button title="Add to Cart" onPress={() => addItem(item.id, 1)} />
</View>
)}
/>
<Text>Cart items: {cart?.getItemCount() ?? 0}</Text>
</View>
);
}| Guide | Description |
|---|---|
| Configuration & Setup | Provider options, storage adapters, session restore |
| Authentication | Guest, Basic Auth, JWT, 2FA |
| Cart API | Add, update, remove items, coupons, shipping |
| Products API | Browse, filter, categories, tags |
| Account API | Profile, orders, downloads, reviews |
| Error Handling | Error hierarchy, catching errors, 2FA flow |
| Hooks Reference | useCart, useCartMutations, useProducts, useAccount, useCoCart |
| Utilities | Currency formatter, timezone helper |
- Documentation — https://cocartapi.com/docs
- Community — https://cocartapi.com/community
- GitHub — https://github.com/cocart-headless
- X — @cocartheadless
CoCart is developed and maintained by CoCart Headless, LLC.
Released under the MIT License.