React Native
Learn how to use Jazz from React Native and Expo apps.React Native and Expo are supported in the beta through jazz-tools/react-native and the direct jazz-rn native dependency. Use a matching development or release build: Expo Go is unsupported. On the web target, jazz-tools/react-native and jazz-tools/expo throw an error that says so: for Expo web, render the web client from jazz-tools/react in a .web.tsx platform file, which signs in with your backend's same-origin cookie like any web app. Its local-first client needs the Expo Metro config.
Setup
React Native and Expo use the same session API as the web, with platform-specific runtime and
account storage adapters. initial: "device" starts people as guests on a
device account, which works offline:
import { JazzProvider } from "jazz-tools/expo";function App() {return (<JazzProvider config={{ serverUrl, initial: "device" }}><TodoApp /></JazzProvider>);}
Install
Use Expo SDK 54 or later (SDK 58 included). Install Jazz with the Expo modules it uses for crypto and
the OS-protected account store, plus babel-preset-expo:
Terminalnpm install jazz-tools jazz-rnnpx expo install expo-crypto expo-secure-store babel-preset-expo
npx expo install picks the babel-preset-expo version that matches your SDK.
jazz-rn ships Jazz's engine prebuilt for Android and iOS, so you don't need a Rust toolchain, but
both platforms' native libraries are always installed: about 160 MB in node_modules. Building the
app needs the usual native toolchains: for Android, the Android SDK (min SDK 24), NDK 27.1.12297006
and CMake 3.22.1 or later, which Android Studio's SDK Manager installs; for iOS, Xcode and
CocoaPods.
Jazz doesn't need jazz-tools/expo/polyfills. It only installs a global ReadableStream, which
Hermes lacks, for code of your own that uses web streams; streaming writes such as
insertStreaming also take an async iterable.
Add the jazz-rn config plugin to app.json:
app.json{"expo": {"plugins": ["jazz-rn"]}}
Let Babel transform import.meta, which Jazz uses:
babel.config.jsmodule.exports = function (api) {api.cache(true);return {presets: [["babel-preset-expo", { unstable_transformImportMeta: true }]],};};
Jazz needs the New Architecture, which is the default from SDK 54. Then build the native app with
npx expo prebuild and npx expo run:android or npx expo run:ios, or with EAS Build. Expo Go
can't load Jazz's native module. After changing the Babel config, start Metro with
npx expo start --clear.
Your schema and its migrations ship in the JavaScript bundle, and the app hands them to the native
module when it starts, so a schema change or a new migration needs no native rebuild: an over-the-air
JavaScript update (EAS Update, say) carries it. Upgrading jazz-tools does need one: its JavaScript
and the jazz-rn native module must come from the same release, so ship it as a new native build
(with EAS Update, a new runtimeVersion), not over the air.
To reach a backend on your computer, the Android emulator uses http://10.0.2.2:<port> instead of
localhost, and Android blocks plain http:// unless you allow cleartext traffic for development.
An Expo app's package is CommonJS, while your backend imports jazz.generated.ts as an ES module.
Keep the app files (jazz.app.json, jazz.permissions.json and jazz.generated.ts) in a folder of
their own (for example jazz/) with a package.json of { "type": "module" }, run
npx jazz-tools generate there, and import app from there in both the app and the backend; see
Your Own Server.
A bare React Native host uses the same direct dependency and New Architecture, with an OS-protected account store. The canonical Expo scaffold shows the complete lifecycle and platform configuration. The beta has not yet proven two physical JSI runtimes attached to one relay.
Loading and errors
JazzProvider renders its children once someone is signed in, loading while the session starts
or switches users, signedOut while no one is signed in, and error when there is no usable client.
Anywhere inside it, those views included, useJazzSession() gives the session's status
("starting", "ready", "signed-out", "transitioning", "error" or "closed"), its user,
its error and its operations, such as retry():
import { JazzProvider, useJazzSession } from "jazz-tools/expo";function StartupError() {const { error, retry } = useJazzSession();return <Button title={`${error?.message}: retry`} onPress={() => void retry()} />;}<JazzProviderconfig={{ serverUrl, initial: "device" }}loading={<ActivityIndicator />}error={<StartupError />}><TodoApp /></JazzProvider>;
A failed operation that leaves the client usable (a refused link, say) keeps the session ready
with error set, so the app keeps working while you show it.
Which entry exports what
Import from jazz-tools/expo in an Expo app and jazz-tools/react-native in a bare one. Both
export JazzProvider, useJazzSession, createJazzClient, useDb, useAll,
useOne and useSyncStatus.
Some bundlers and runtimes cannot automatically resolve Jazz's Wasm and worker assets. See Wasm loading.
Sign in through your backend
An app has no cookie for your backend, so it hands Jazz its own token instead. Pass bearer, a
function that returns the token your app holds for its backend (or null when signed out), next
to serverUrl in the config of <JazzProvider> (or createJazzClient) from
jazz-tools/react-native or jazz-tools/expo. Jazz sends it as Authorization: Bearer … when it
signs in and on the device's sync connection, so your backend's authenticate reads that header
instead of a cookie.
<JazzProvider config={{ serverUrl, initial: "device", bearer: () => tokenStore.current() }}><TodoApp /></JazzProvider>
Your backend decides who is signed in, and the session follows it. After your own sign-in, call
refresh() from useJazzSession() to sign in to the user's own account, or linkDeviceAccount()
to keep a guest's data under the new user; signOut() signs out. Linking a user who already has an
account fails with an AccountAuthError whose code is link_refused; sign them in with refresh()
instead.
To reach a development backend over plain http:// on Android, allow cleartext traffic, for
example with expo-build-properties (android.usesCleartextTraffic: true) in a development build
only.
Developing on a physical device
On a device, Jazz syncs over plaintext (http://, ws://) only with the machine it runs on:
localhost, a loopback address, or an Android emulator's host (10.0.2.2, 10.0.3.2). Any other
host, a LAN address like http://192.168.1.20:4200 or a .local name included, needs https://:
otherwise the session's token would travel unencrypted on your network. Jazz refuses such a URL with
an error whose code is remote_plaintext_endpoint.
To reach the backend on your development machine from a physical device:
- Android over USB: forward the port, then use
localhostas on an emulator:adb reverse tcp:4200 tcp:4200(with your backend's port), andserverUrl: "http://localhost:4200/jazz". - iOS, or Android without USB: put the backend behind a TLS tunnel with a publicly trusted
certificate, such as
cloudflared tunnel --url http://localhost:4200ortailscale serve, and use itshttps://URL.
A certificate from your own development CA (for example mkcert) doesn't work for Jazz's sync connection yet, even when the device trusts the CA: on iOS and Android, Jazz's native connection trusts only the standard public certificate authorities. Use a tunnel instead.
Testing without a device
Test your schema, permissions and backend logic in Node against your app's backend, as in
Testing. A Node client stands in for the
device: createJazzClient from jazz-tools/client keeps its account in memory by default there,
and needs a store only for a device account (the testing page shows an in-memory one).
Use bearer: () => testJazz.bearer(userId) to sign in the way the app does. The React Native UI
itself needs an emulator or a device.