Skip to main content
This guide covers React Native-specific features of the Jade SDK, including storage adapters and app state handling.
For a complete working example, see the React Native example app with chat UI, media gallery, and custom tool UIs.

Storage Adapters

The React Native SDK requires a storage adapter for persisting data like session state, authentication tokens, and preferences.

AsyncStorage Adapter

The most common storage solution using @react-native-async-storage/async-storage:

Custom Storage Adapter

Implement your own storage adapter for alternative storage solutions:
Example with MMKV for better performance:

Secure Storage with Keychain

For sensitive data like API keys:

Storage Keys

The SDK uses these predefined storage keys:
Import and use these keys:

Accessing Storage in Components

Use the useStorage hook to access the storage adapter:

App State Handling

React Native apps transition between foreground and background states. The Jade SDK handles these transitions automatically.

Default Behavior

By default, the SDK:
  • Pauses streaming when the app goes to background
  • Maintains connection state for reconnection
  • Resumes automatically when the app returns to foreground

useAppState Hook

Monitor app state in your components:

App State Values

Conditional UI

Show different UI based on app state:

Disable Background Pause

For apps that need to continue streaming in the background:
Streaming in the background consumes battery and may be terminated by the OS. Consider using push notifications for long-running operations instead.

Manual Reconnection

Handle reconnection manually for more control:

Session Recovery

Recover session state after app restart:

Background Execution

iOS Background Modes

For iOS, if you need limited background execution, configure in Info.plist:
Background execution is limited on iOS. For long-running tasks, consider using server-side processing with push notifications.

Android Keep-Alive

For Android apps that need to stay alive:

SSE Streaming

The React Native SDK uses react-native-sse for Server-Sent Events, which is bundled automatically. No additional configuration is required.

Differences from Web


Streaming State

The useJadeSession hook provides detailed streaming state for building rich UIs:

Building a Tool Execution UI


Complete Example

Best Practices

Use AsyncStorage or MMKV for general data persistence
Use Keychain for sensitive data like API keys
Let the SDK handle background pausing automatically
Show clear UI when streaming is paused
Persist session ID for recovery after app termination
Check session status before reconnecting
Use push notifications for long-running operations
Test background/foreground transitions thoroughly