React Native SDK
Use @perkamo/react-native for bare React Native 0.73+ and Expo apps. It ships the same provider and hooks as the React SDK plus a client tuned for mobile runtimes.
Install
npm install @perkamo/react-nativeClient and provider
Never bundle server API keys in a mobile app. Your backend exposes the token route described in the React SDK. The app requests short-lived client tokens through getToken:
import {
createPerkamoReactNativeClient,
PerkamoProvider,
usePerkamoCustomerJson,
} from "@perkamo/react-native";
import { Text } from "react-native";
const perkamo = createPerkamoReactNativeClient({
getToken: async () => {
const response = await fetch("https://app.example.com/auth/perkamo/token", {
method: "POST",
headers: { authorization: `Bearer ${await getMySessionToken()}` },
});
const body = await response.json();
return body.token;
},
});
export function App() {
return (
<PerkamoProvider client={perkamo}>
<LoyaltyBadge />
</PerkamoProvider>
);
}
function LoyaltyBadge() {
const { customer, loading, error } = usePerkamoCustomerJson();
if (loading || error || !customer) return null;
return <Text>Level {customer.level.level}</Text>;
}Emit events
await perkamo.emit("workout.completed", { minutes: 30 });Client events are validated against the token scope. Keep purchases, subscriptions and other business-critical events on your backend with a server SDK.
Live updates without EventSource
React Native has no EventSource, so both subscribeCustomer and the usePerkamoCustomerStream() hook poll the customer endpoint instead of opening an SSE stream. The callback fires only when the customer actually changed. Tune the cadence with subscribePollIntervalMs (default 15000 ms, minimum 1000 ms):
const perkamo = createPerkamoReactNativeClient({
getToken,
subscribePollIntervalMs: 30_000,
});No stream token is needed for polling; it reuses the regular client token. See Realtime streaming for how browser apps stream over SSE.
Security boundary
- Never ship server API keys or signing secrets inside the app bundle. App
binaries can be unpacked and inspected.
- The client accepts only
getToken; passing server-secret option names
throws at runtime.
- The client requires HTTPS API endpoints.
- Read Security and keys before shipping a mobile
integration.