> ## 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 quickstart

> Wire a React frontend to an app's exposed functions

## Create the project

[Create your first app](https://docs.bijection.com/start/quickstart.md) scaffolds the React and Vite notes
starter. Its frontend is `apps/main/src/main.tsx`; its app tree is
`bijection/app.ts`.

## Connect, watch and mutate

```tsx apps/main/src/main.tsx theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { useState } from "react";
import { createRoot } from "react-dom/client";
import { app, connect } from "../../../.bijection/_generated/client";
import { Bijection, useMutation, useWatch } from "@bijectionhq/bijection/react";
const client = connect(import.meta.env.VITE_BIJECTION_URL);

function Notes() {
  const listed = useWatch(app.notes.recentNotes);
  const add = useMutation(app.notes.add);
  const [error, setError] = useState<string>();

  async function addNote() {
    const added = await add({ text: "New note" });
    setError(added.ok ? undefined : added.message);
  }

  return (
    <>
      <button disabled={add.pending} onClick={() => void addNote()}>Add note</button>
      {error ? <p role="alert">{error}</p> : null}
      {listed?.ok ? listed.value.map((note) => <p key={note.id}>{note.text}</p>) : null}
    </>
  );
}

createRoot(document.getElementById("root")!).render(
  <Bijection client={client}>
    <Notes />
  </Bijection>,
);
```

The generated `app` export gives typed references to the app’s exposed functions. `useWatch` keeps the latest notes live, and `useMutation` answers a
`Result`: `{ ok: true, value }`, or `{ ok: false, code, message }` for a
`ctx.refuse(code, message)` or a host refusal. The form needs no
`try`/`catch`.

## Add Bijection to an existing React frontend

1. Install `@bijectionhq/bijection` in the frontend package.
2. Set `"browserClient": true` in the backend's `bijection.json` and run
   `bijection check --write-lock`. Import `app` and `connect` from
   `.bijection/_generated/client.ts` in that project.
3. Set the installation URL, for example as `VITE_BIJECTION_URL`.
4. Connect once and wrap the tree in `<Bijection client>`, as above.

To sign people in, see [Connect and authenticate](https://docs.bijection.com/clients/react/configuration.md).

## Deploy

Follow [Create your first app](https://docs.bijection.com/start/quickstart.md) and
[Frontend installations](https://docs.bijection.com/operate/installations/frontend).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.