Skip to content

React Native

The React Native entrypoint includes the provider and hooks. Supply your application’s authenticated user UUID, a credential callback, and a storage adapter such as AsyncStorage:

import AsyncStorage from "@react-native-async-storage/async-storage";
import { StreaklineProvider } from "@streakline/sdk/react-native";
export function ProgressProvider({ userId, children }) {
return (
<StreaklineProvider
baseUrl="https://api.qa.streakline.dev"
cacheNamespace="my-product:qa"
userId={userId}
storage={AsyncStorage}
getCredential={() => api.createStreaklineClientCredential()}
>
{children}
</StreaklineProvider>
);
}

api.createStreaklineClientCredential() represents your authenticated backend call. It must return the full structured credential response. The provider starts the client when mounted and stops it when unmounted.

import { Button, Text, View } from "react-native";
import { useStreakline, useStreaklineProfile } from "@streakline/sdk/react-native";
export function LessonProgress({ completionId }) {
const streakline = useStreakline();
const profile = useStreaklineProfile();
return (
<View>
<Text>{profile?.total_score ?? 0} points</Text>
<Button title="Record completion" onPress={() => {
void streakline.track("lesson.completed", {
idempotencyKey: `lesson:${completionId}`,
}).catch(reportError);
}} />
</View>
);
}

Replace reportError with your app’s error handler. Record the event when the product action really completes; the button above illustrates the SDK call. The score label should follow your own configured product vocabulary.

useStreaklineProfile() subscribes to profile changes. useStreaklineModel() exposes the cached scoring model. Both can return null before data is available.

The SDK persists its model, profile, and event queue through the supplied adapter. Credentials remain in memory. Predictions reconcile when events reach the API. Your app’s own data storage and synchronization remain your responsibility.

Inspect getLastFlushErrorSnapshot() for background failures and getQuarantinedEventsSnapshot() for isolated invalid events. These changes notify subscribers.

Call await streakline.clearUserData() when clearing the previous user’s local state after logout or account erasure. Remount with the next user’s identity. Local storage is partitioned by user ID and cacheNamespace; the credential controls authorization.