Skip to main content
Learn how to create a React app, built with Vite, with a Bijection backend, starting from the react-vite template of bijection init.
1

Install the Bijection CLI

If bijection is not on your PATH afterwards, add it as the installer explains. See Install Bijection.
2

Create the app

This writes a React app and its Bijection backend into my-app/, then installs the app’s dependencies, including the Bijection SDK, with your JavaScript package manager: the one of an enclosing workspace, otherwise the first of pnpm, bun, yarn and npm on your PATH. The app needs Node.js and one of them; the backend does not. Last, it generates bijection/_generated/, the typed API of your functions, so the project typechecks before it has a deployment.
3

Log in

Log this machine in to Bijection. You only do this once per machine.
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:
4

Start the backend

The first run creates your dev deployment and writes its URL to .env.local, where the app reads it as VITE_BIJECTION_URL. bijection dev then keeps running: on every change it pushes bijection/ to your dev deployment and regenerates bijection/_generated/. Keep it running.
5

Start the app

In another terminal, start the app with the command bijection init printed for your package manager, for example:
Open http://localhost:5173/ and send a message. Open a second window: messages appear in both as soon as they are sent.
6

Read the backend

bijection/schema.ts declares the messages table, and bijection/messages.ts exports a query and a mutation. Each export is an API function named after the file and the export: api.messages.list and api.messages.send.
bijection/messages.ts
7

Read the app

src/main.tsx creates a BijectionReactClient for the deployment URL and provides it to the app with BijectionProvider:
src/main.tsx
src/App.tsx subscribes to the query with useQuery and calls the mutation with useMutation. The query result updates by itself whenever the messages change:
src/App.tsx
8

Call a function from the CLI

With the app open, send a message from another terminal. It appears in the app at once:
See the complete React documentation.