Below is the recipe that most teams follow today to make a React Native (Expo or bare-RN) app talk to the exact same Convex backend that their web (Next.js) app already uses.
The high-level idea
- The Convex “frontend” client is just TypeScript that runs in any browser-like environment.
- React Native is almost a browser-like environment, it just doesn’t ship with some globals (crypto, URL, etc.).
- Once we polyfill those globals we can import the normal Convex client, wrap our component tree in
<ConvexProvider> and start calling our queries/mutations exactly the same way we do in Next.js.
───────────────────────────────────────────────────────────
- Create a monorepo (optional but highly recommended)
───────────────────────────────────────────────────────────
web/ ← your Next.js app
mobile/ ← your React Native / Expo app
convex/ ← generated Convex code + backend functions
package.json
pnpm-workspace.yaml | yarn workspaces | npm workspaces
This lets both apps share the same convex/_generated/ folder so the auto-generated hooks stay in sync.
───────────────────────────────────────────────────────────
2. Install the Convex client in the mobile package
───────────────────────────────────────────────────────────
cd mobile
or expo install if you’re using Expo
npm install convex
───────────────────────────────────────────────────────────
3. Add the missing polyfills once, at the real entry point
───────────────────────────────────────────────────────────
Most of these are one-liners:
// mobile/App.tsx (or index.js if you ejected)
// 1️⃣ URL / URLSearchParams
import 'react-native-url-polyfill/auto';
// 2️⃣ crypto.getRandomValues (needed for Convex auth & ids)
import 'react-native-get-random-values';
// 3️⃣ Buffer (needed by some node-style libs)
import { Buffer } from 'buffer';
global.Buffer = Buffer;
// 4️⃣ (only if you hit a “TextEncoder/TextDecoder is not defined” error)
import { TextEncoder, TextDecoder } from 'text-encoding';
if (!global.TextEncoder) global.TextEncoder = TextEncoder;
if (!global.TextDecoder) global.TextDecoder = TextDecoder;
After those imports you can treat the environment just like the browser.
───────────────────────────────────────────────────────────
4. Wrap the component tree in ConvexProvider
───────────────────────────────────────────────────────────
import React from 'react';
import { ConvexProvider, ConvexReactClient } from 'convex/react';
import { SafeAreaView, Text } from 'react-native';
// Generated hooks come from the shared folder
import { api } from '../convex/_generated/api';
const convex = new ConvexReactClient(
// The same deployment URL you use on the web
'https://acme.convex.cloud'
);
export default function App() {
return (
<SafeAreaView style={{ flex: 1 }}>
);
}
function HomeScreen() {
// identical code to your Next.js component ⤵️
const messages = useQuery(api.messages.list); // live query
const sendMessage = useMutation(api.messages.send); // mutation
return (
<>
{messages?.map((m) => (
{m.body}
))}
</>
);
}
───────────────────────────────────────────────────────────
5. Authentication (share your users between web & mobile)
───────────────────────────────────────────────────────────
Convex supports custom authentication providers.
In many apps the web side uses Next-Auth, Clerk, Auth0, etc.
The mobile side can either:
A. Use the same provider’s React Native SDK (e.g. @clerk/clerk-expo, auth0-react-native) and then call your Convex loginWithProvider mutation with the provider’s JWT, or
B. Skip auth entirely at first (Convex will treat everyone as the anonymous user) and wire it up later—nothing in the above setup changes when you add auth.
───────────────────────────────────────────────────────────
6. Typical gotchas & how to fix them
───────────────────────────────────────────────────────────
❌ Metro bundler can’t resolve “crypto” / “stream”.
👉 You forgot react-native-get-random-values or buffer.
❌ TextEncoder is not defined.
👉 Add the optional polyfill snippet shown above.
❌ TypeScript can’t find api.messages.list.
👉 Make sure mobile/tsconfig.json’s baseUrl or paths
includes ../convex. In a monorepo this is usually automatic.
───────────────────────────────────────────────────────────
7. Dev workflow quality-of-life tips
───────────────────────────────────────────────────────────
• Run convex dev once at the repo root; both web & mobile will hot-reload when you change Convex functions.
• Put shared UI & business-logic code in a “packages/common” folder so neither app drifts.
• Ship an OTA update on Expo while the backend code stays in Convex—no store submission needed for most features 🎉.
And that’s it—after those polyfills the experience is exactly like building with Convex on the web: live queries, mutations, and optimistic updates all work out of the box. Happy hacking!