Using Convex
Edit page
Add a database to your app with Convex.
For the complete documentation index, see llms.txt. Use this file to discover all available pages.
Convex is a backend platform for building reactive apps with a realtime database, server functions, file storage, search, scheduling, and type-safe client libraries without the need for cluster management, SQL, or ORMs.
The EAS CLI integration can create and connect the Convex project for you. It replaces the manual setup steps where you install the package, create a Convex team and project, copy deployment URLs, and configure EAS environment variables.
3 requirements
3 requirements
1.
Sign up for an Expo account.
2.
npm install -g eas-cli.3.
Create an Expo project and link it to EAS with eas init.
Connect Convex with EAS
1
Run the EAS CLI integration command
From your Expo project directory, run:
- eas integrations:convex:connectThe command will prompt for a Convex deployment region, project name, and team name when needed. It only asks for a team name when it needs to create a new Convex team connection.
You can also pass values explicitly:
- eas integrations:convex:connect --region aws-us-east-1 --team-name "Your-team-name" --project-name "your-app"The integration command:
- Installs the
convexpackage withnpx expo install convex - Creates a Convex team connection for your EAS account, or reuses an existing one
- Creates a Convex project and deployment for the current Expo app
- Writes
CONVEX_DEPLOY_KEYandEXPO_PUBLIC_CONVEX_URLto .env.local - Creates or updates the
EXPO_PUBLIC_CONVEX_URLEAS project environment variable for the production, preview, and development environments - Sends an invitation to your verified email so you can claim the Convex team and open the Convex dashboard
2
3
Add a Convex provider
Create a Convex client with the deployment URL that the EAS integration wrote to .env.local, then wrap your app in ConvexProvider.
For an Expo Router project, update src/app/_layout.tsx:
import { ConvexProvider, ConvexReactClient } from 'convex/react'; import { Stack } from 'expo-router'; const convex = new ConvexReactClient(process.env.EXPO_PUBLIC_CONVEX_URL!, { unsavedChangesWarning: false, }); export default function RootLayout() { return ( <ConvexProvider client={convex}> <Stack /> </ConvexProvider> ); }
4
Query Convex from your app
Add a query function in the convex directory:
import { query } from './_generated/server'; export const get = query({ args: {}, handler: async ctx => { return await ctx.db.query('tasks').collect(); }, });
Then call it from your app with useQuery:
import { api } from '@/convex/_generated/api'; import { useQuery } from 'convex/react'; import { Text, View } from 'react-native'; export default function Index() { const tasks = useQuery(api.tasks.get); return ( <View> {tasks?.map(task => ( <Text key={task._id}>{task.text}</Text> ))} </View> ); }
To learn more about how Convex works, including database documents, functions, and client subscriptions, see the Convex overview:
Learn the core Convex concepts behind database documents, functions, and realtime client updates.
Manage the integration
Use these commands to inspect or manage the Convex integration later:
- eas integrations:convex:project- eas integrations:convex:dashboard- eas integrations:convex:team- eas integrations:convex:team:inviteIf you remove the link with eas integrations:convex:project:delete or eas integrations:convex:team:delete, EAS removes its integration metadata. These commands do not destroy resources on Convex.