> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bijection.com/llms.txt
> Use this file to discover all available pages before exploring further.

# React Native Quickstart

> Add Bijection to a React Native Expo project

Learn how to query data from Bijection in a React Native app.

<Steps>
  <Step title="Install the Bijection CLI">
    ```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
    curl -fsSL https://bijection.com/install.sh | sh
    ```

    See [Install Bijection](/get-started/install) for PATH setup and supported
    platforms.
  </Step>

  <Step title="Create a React Native app">
    Create a React Native app using the `npx create-expo-app` command.

    ```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
    npx create-expo-app my-app
    ```
  </Step>

  <Step title="Add a Bijection backend">
    In the app's directory, run `bijection init`. It adds a `bijection/` folder,
    where you write your backend functions, with a sample schema, query and
    mutation, and `bijection.json`.

    ```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
    cd my-app && bijection init
    ```
  </Step>

  <Step title="Add the Bijection SDK to the app">
    The Bijection SDK (`bijection/react`, `bijection/browser`, …) is not published
    to the npm registry. Your app declares it as a tarball from bijection.com, for
    the version of your CLI (`bijection --version` prints it). Add this line to the
    `dependencies` in your app's `package.json`:

    ```json package.json theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
    "bijection": "https://bijection.com/sdk/bijection-0.1.1.tgz"
    ```

    Then install your app's dependencies with its package manager as usual (for
    example `npm install`). The `react-vite` and `nextjs` templates of
    `bijection init` write this line and run the install for you.
  </Step>

  <Step title="Set up a Bijection dev deployment">
    Log this machine in to Bijection, once per machine, then run
    `bijection dev`. The first run creates your dev deployment and saves its URL
    in `.env.local` as `EXPO_PUBLIC_BIJECTION_URL`. The `dev` command then
    keeps running to push your functions in `bijection/` to your dev deployment
    on every change.

    ```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
    bijection login
    bijection dev
    ```

    <Note>
      Bijection's hosted service is not yet open for public sign-up, and the CLI
      has no default management service. Before running `bijection login`, set
      `BIJECTION_MANAGEMENT_URL` to the management service URL you were given, in
      your shell's startup file so that every later `bijection` command sees it too:

      ```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
      export BIJECTION_MANAGEMENT_URL=https://<your management service>
      ```
    </Note>
  </Step>

  <Step title="Create sample data for your database">
    Create a `sampleData.jsonl`
    file with some sample data.

    ```json theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
    {"text": "Buy groceries", "isCompleted": true}
    {"text": "Go for a swim", "isCompleted": true}
    {"text": "Integrate Bijection", "isCompleted": false}
    ```
  </Step>

  <Step title="Add the sample data to your database">
    Now that your project is ready, add a `tasks` table with the sample data into
    your Bijection database with the `import` command.

    ```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
    bijection import --table tasks sampleData.jsonl
    ```
  </Step>

  <Step title="Declare the tasks table">
    `bijection init` created `bijection/schema.ts`, which declares the tables of
    your database, starting with a sample `messages` table. Add a `tasks` table
    beside it. The schema gives your functions TypeScript types, and Bijection
    enforces it at runtime.

    ```ts bijection/schema.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
    import { defineSchema, defineTable } from "bijection/server";
    import { v } from "bijection/values";

    export default defineSchema({
      messages: defineTable({
        author: v.string(),
        body: v.string(),
      }),
      tasks: defineTable({
        text: v.string(),
        isCompleted: v.boolean(),
      }),
    });
    ```
  </Step>

  <Step title="Expose a database query">
    Add a new file `tasks.ts` in the `bijection/` folder
    with a query function that loads the data.

    Exporting a query function from this file
    declares an API function named after the file
    and the export name, `api.tasks.get`.

    ```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
    import { query } from "./_generated/server";

    export const get = query({
      args: {},
      handler: async (ctx) => {
        return await ctx.db.query("tasks").collect();
      },
    });
    ```
  </Step>

  <Step title="Reset the Expo project">
    If you haven't done so yet, reset the Expo project to get a fresh
    `app` directory.

    ```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
    npm run reset-project
    ```
  </Step>

  <Step title="Connect the app to your backend">
    In `_layout.tsx`, create a `BijectionReactClient` and pass it to a `BijectionProvider`
    wrapping your component tree.

    ```tsx {1,4-6,10,14} theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
    import { BijectionProvider, BijectionReactClient } from "bijection/react";
    import { Stack } from "expo-router";

    const bijection = new BijectionReactClient(process.env.EXPO_PUBLIC_BIJECTION_URL!, {
      unsavedChangesWarning: false,
    });

    export default function RootLayout() {
      return (
        <BijectionProvider client={bijection}>
          <Stack>
            <Stack.Screen name="index" />
          </Stack>
        </BijectionProvider>
      );
    }
    ```
  </Step>

  <Step title="Display the data in your app">
    In `index.tsx` use the `useQuery` hook to fetch
    from your `api.tasks.get` API.

    ```tsx {1-2,6,15} theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
    import { api } from "@/bijection/_generated/api";
    import { useQuery } from "bijection/react";
    import { Text, View } from "react-native";

    export default function Index() {
      const tasks = useQuery(api.tasks.get);
      return (
        <View
          style={{
            flex: 1,
            justifyContent: "center",
            alignItems: "center",
          }}
        >
          {tasks?.map(({ _id, text }) => (
            <Text key={_id}>{text}</Text>
          ))}
        </View>
      );
    }
    ```
  </Step>

  <Step title="Start the app">
    Start the app, scan the provided QR code with your phone,
    and see the serialized list of tasks in the center of the screen.

    ```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
    npm start
    ```
  </Step>
</Steps>

React native uses the same library as React web. See the complete
[React documentation](/client/react/overview).
