Skip to main content
React Native support is available from modelence v0.19.0.
Modelence’s client library works in React Native. Because React Native lacks browser APIs like localStorage and window, you configure the client with configureClient so the SDK knows how to store auth tokens, read device dimensions, and resolve server URLs.

Setup

1

Install dependencies

Add Modelence to your React Native project:
You’ll also need @react-native-async-storage/async-storage (or any other persistent key-value store) to persist the auth token across app restarts.
2

Configure the client

Call configureClient once, before your app mounts — for example at the top of your entry file (App.tsx or index.ts).
3

Wrap your app with AppProvider

Load the persisted auth token before mounting your app, then wrap your root component with AppProvider:

ClientConfig reference

Using authentication

Auth functions work the same way as on the web:

Calling methods

callMethod works without any changes — it automatically prepends baseUrl to every request:

Live queries and WebSockets

Live queries connect over WebSocket to baseUrl. No additional configuration is needed beyond configureClient:

OAuth sign-in

For Google or GitHub sign-in, Modelence opens an OAuth URL in the browser. On React Native, provide openUrl in configureClient so the SDK can hand off to the device browser via Linking.openURL:
After the OAuth flow completes, the provider redirects back to your app via a deep link. Configure your deep link scheme to call loginWithOAuth with the returned token.

Notes

  • No AppProvider required for auth-only usage. You can call loginWithPassword, callMethod, etc. without AppProvider. The provider is needed only if you use React hooks like useSession or useQuery.
  • Token persistence is your responsibility. Modelence calls setAuthToken and getAuthToken but does not bundle a storage library. Use AsyncStorage, expo-secure-store, or any store that fits your security requirements.
  • orientation in ClientInfo is optional. Pass null if your app does not track orientation.