@drakkar.software/anchor-adapter-react-native
v1.3.0
Published
React Native platform adapters for Anchor (expo-sqlite, AsyncStorage)
Readme
Installation
npm install @drakkar.software/anchor @drakkar.software/anchor-adapter-react-native zustand @supabase/supabase-jsInstall the peer dependencies you need:
# Persistence (pick one or both)
npx expo install expo-sqlite
npm install @react-native-async-storage/async-storage
# Network detection
npm install @react-native-community/netinfo
# Background sync
npx expo install expo-task-manager expo-background-fetch
# OAuth deep links
npx expo install expo-linkingAll peer dependencies are optional -- install only the ones your app uses.
Adapters
ExpoSqliteAdapter
Persistence adapter backed by expo-sqlite. Recommended for structured data and larger datasets.
import { ExpoSqliteAdapter } from '@drakkar.software/anchor-adapter-react-native'
createSupabaseStores({
persistence: { adapter: new ExpoSqliteAdapter() },
})AsyncStorageAdapter
Persistence adapter backed by @react-native-async-storage/async-storage. Simple key-value fallback.
import { AsyncStorageAdapter } from '@drakkar.software/anchor-adapter-react-native'
createSupabaseStores({
persistence: { adapter: new AsyncStorageAdapter() },
})RNNetworkStatus
Detects online/offline state using @react-native-community/netinfo. Enables automatic offline queue flush on reconnect.
import { RNNetworkStatus } from '@drakkar.software/anchor-adapter-react-native'
createSupabaseStores({
network: new RNNetworkStatus(),
})RNAppLifecycle
Detects foreground/background transitions using React Native's AppState API. Enables auto-revalidation and queue flush when the app returns to the foreground.
import { RNAppLifecycle } from '@drakkar.software/anchor-adapter-react-native'
import { setupAppLifecycle } from '@drakkar.software/anchor'
setupAppLifecycle({
adapter: new RNAppLifecycle(),
stores: [stores.todos, stores.profiles],
})RNBackgroundSync
Flushes the offline mutation queue in the background using expo-task-manager and expo-background-fetch.
import { RNBackgroundSync } from '@drakkar.software/anchor-adapter-react-native'
import { setupBackgroundSync } from '@drakkar.software/anchor'
await setupBackgroundSync(offlineQueue, new RNBackgroundSync())createExpoOAuthHandler
Handles OAuth flows with Supabase using Expo deep links (expo-linking).
import { createExpoOAuthHandler } from '@drakkar.software/anchor-adapter-react-native'
const oauth = createExpoOAuthHandler(supabase)
await oauth.signInWithGoogle()Full Example
import { createClient } from '@supabase/supabase-js'
import { createSupabaseStores, setupAppLifecycle, setupBackgroundSync } from '@drakkar.software/anchor'
import {
ExpoSqliteAdapter, RNNetworkStatus, RNAppLifecycle, RNBackgroundSync,
} from '@drakkar.software/anchor-adapter-react-native'
import type { Database } from './database.types'
const supabase = createClient<Database>(SUPABASE_URL, SUPABASE_ANON_KEY)
const stores = createSupabaseStores<Database>({
supabase,
tables: ['todos', 'profiles'],
persistence: { adapter: new ExpoSqliteAdapter() },
network: new RNNetworkStatus(),
realtime: { enabled: true },
})
setupAppLifecycle({
adapter: new RNAppLifecycle(),
stores: [stores.todos, stores.profiles],
authStore: stores.auth,
})
await setupBackgroundSync(offlineQueue, new RNBackgroundSync())Related Packages
| Package | Description |
|---------|-------------|
| @drakkar.software/anchor | Core library |
| @drakkar.software/anchor-adapter-web | Web adapters |
Documentation
Full documentation: github.com/Drakkar-Software/Anchor
License
MIT
