React Native
Overview
The @recursiv/sdk works in React Native and Expo with zero additional dependencies. It uses the runtime’s native fetch implementation. However, agent streaming (chatStream) does not work in React Native due to missing ReadableStream support. This guide covers installation, basic usage, auth flow, and the complete streaming workaround.
Installation
Or with npm:
No native modules, no linking, no polyfills needed. The SDK is pure ESM JavaScript with zero dependencies.
Basic usage
Auth flow with SecureStore
Use expo-secure-store to store session tokens and API keys securely. Never use AsyncStorage for sensitive data — it stores data unencrypted on disk.
Agent streaming workaround
r.agents.chatStream() does not work in React Native. React Native’s fetch implementation does not support ReadableStream, which is required for SSE (Server-Sent Events) parsing.
The workaround is to use react-native-sse or manual fetch with line-by-line SSE parsing.
Install react-native-sse
Streaming utility
React component
Common pitfalls
1. Do not use chatStream()
This is the most common mistake. React Native does not support ReadableStream on fetch responses. Always use the manual SSE approach shown above.
2. Store keys in SecureStore, not AsyncStorage
3. Use machine IP for local development
When developing against a local Recursiv instance, use your machine’s IP address instead of localhost. React Native runs on a separate device/simulator that cannot resolve localhost to your development machine.
To find your machine’s IP:
4. Handle network errors gracefully
Mobile networks are unreliable. Always wrap SDK calls in try/catch:
5. Configure timeout for slow networks
Mobile networks can be slow. Consider increasing the default timeout:
Expo configuration
No special Expo configuration is required. The SDK works with the managed workflow out of the box.