---
title: "Quickstart: web and React"
overline: QUICKSTART
nav: Web / React
updated: 2026-12
minutes: 5
next: multi-app-sync
---

# Quickstart: add Kovlet sync to a web or React app

Add live, shared data to a web or React app in about five minutes. Your app won't need an API key: people sign in to Kovlet and approve it the first time they use it.

> **What you'll build**
>
> - A todo list that stays in sync across browser tabs, devices and every other app on the same [Data Space](/docs/glossary#data-space "Typed tables plus a tree of files, shared live by every app that has access to it.").
> - It works offline: changes are saved in the browser and sent when the connection comes back.
> - You'll need a web project (React, or plain TypeScript) and a free Kovlet account, or a [local Kovlet server](/docs/run-locally).

## Before you start

You need a Kovlet server to connect to. Either:

- Use the hosted API at `https://api.kovlet.com`. The free plan is enough for testing, and you sign in on the console at `https://kovlet.com`.
- Or run `kovletd --dev` on your machine, from the `ghcr.io/kovlethq/kovletd` Docker image or the `kovletd` binary. [Run Kovlet locally](https://kovlet.com/docs/run-locally) starts it and shows how to approve your app from the terminal.

## 1. Install

```sh title="terminal"
npm i @kovlet/client @kovlet/react
```

## 2. Declare the space and sign in

Create `kovlet.ts`. It names your app and lists the tables it needs. There's no key to paste.

```ts title="kovlet.ts" hl="4,7,11"
import { createKovletClient, t } from "@kovlet/client";

export const kovlet = createKovletClient({
  appName: "Todos", // shown on the consent screen and in the console
  autoConnect: false, // browsers block popups that a click didn't open
  spaces: {
    main: {
      role: "editor",
      files: true,
      tables: {
        todos: { title: t.string(), done: t.boolean(), attachment: t.fileRef().optional() },
      },
    },
  },
});

// A stored session resumes on later loads without a popup.
void kovlet.ready.then(() => kovlet.session && kovlet.connect().catch(() => {}));
```

- **Line 4:** `appName` is what people see when they approve your app.
- **Line 7:** `main` is a [slot](/docs/glossary#slot "A named placeholder for a Data Space in your app's code. The person approving the app chooses which space fills it."). When someone approves the app, they pick which of their Data Spaces fills it, or create a new one. The app asks for the `editor` role, so it can read and write.
- **Line 11:** your table and its columns. Every app on the space sees the same types.

`kovlet.connect()` opens Kovlet's consent page in a popup, or a redirect if popups are blocked. Browsers only allow popups that a click opened, so `autoConnect: false` waits for a button (step 3).

The person approves once per browser. The session is tied to a key that the browser keeps in IndexedDB and can't export, and it refreshes itself. The last line reconnects a returning visitor as soon as `kovlet.ready` finds that stored session, with no popup and no click.

> **Tip:** The API defaults to `https://api.kovlet.com`, and sign-in opens on `https://kovlet.com`. For a local `kovletd --dev`, pass `url: "http://127.0.0.1:8080"` and `consoleUrl: "http://localhost:5173"`. [Run Kovlet locally](https://kovlet.com/docs/run-locally) starts both with one Docker command.

## 3. Sync a table

Wrap your app in `KovletProvider`, then read the table with `useTable`.

<!-- tabs: Framework -->

### React

```tsx title="App.tsx" hl="15,20,25"
import { KovletProvider, useSpace, useSyncStatus, useTable } from "@kovlet/react";
import { kovlet } from "./kovlet";

export function App() {
  return (
    <KovletProvider client={kovlet}>
      <Todos />
    </KovletProvider>
  );
}

function Todos() {
  const status = useSyncStatus();
  const main = useSpace<typeof kovlet>("main");
  const todos = useTable(main.table("todos"), { orderBy: "title" });
  if (status.state === "signed-out") return <button onClick={() => kovlet.connect()}>Connect to Kovlet</button>;
  return (
    <>
      <button onClick={() => main.table("todos").insert({ title: "New todo", done: false })}>Add</button>
      <ul>
        {todos.map((t) => (
          <li key={t.id} onClick={() => main.table("todos").update(t.id, { done: !t.done })}>
            {t.done ? "✓" : "○"} {t.title}
          </li>
        ))}
      </ul>
      <p>{status.state}</p>
    </>
  );
}
```

### Without React

```ts title="main.ts" hl="6,10"
import { kovlet } from "./kovlet";

const todos = kovlet.space("main").table("todos");
const list = document.querySelector("#todos");

todos.subscribe((rows) => {
  if (list) list.innerHTML = rows.map((row) => `<li>${row.done ? "✓" : "○"} ${row.title}</li>`).join("");
});

document.querySelector("#add")?.addEventListener("click", () => todos.insert({ title: "New todo", done: false }));
document.querySelector("#connect")?.addEventListener("click", () => void kovlet.connect());
```

<!-- /tabs -->

Reads come from a copy of the data kept in the browser, so they're instant and synchronous. Writes show up at once, wait in IndexedDB while you're offline, and then sync. Every other app on the space sees them live. Outside React, `table.all()` returns the rows and `table.subscribe(rows => …)` calls you on every change.

> **You should see**
>
> - Before sign-in, a *Connect to Kovlet* button. Press it, sign in on Kovlet's consent page, and approve the app.
> - Then an *Add* button, an empty list and the status `live`.
> - *Add* puts "○ New todo" in the list. Clicking the row turns it into "✓ New todo". Open a second tab: it updates too.
> - The row is also in the console: open the Data Space and its `todos` table.

## 4. Pick or create a space (optional)

On first sign-in, the person maps the `main` slot to one of their spaces, or presses Approve and gets a new space named after the app. To always use one particular space, set `spaceId` on the slot.

Once someone is signed in, your app can manage its own spaces without sending them to the console:

```ts title="spaces.ts" hl="4,6"
import { kovlet } from "./kovlet";

export async function ensureSpace() {
  const { spaces, can_create } = await kovlet.listSpaces();
  if (!spaces.some((s) => s.name === "Todos") && can_create) {
    await kovlet.createSpace({ name: "Todos", slug: "todos" }); // this app gets editor
  }
}
```

`createSpace` also takes `slot`: the name of a slot you declared in `spaces` (here only `main`). That slot then syncs the new space instead. A slot name you didn't declare maps nothing.

To ask for access to another existing space, call `kovlet.requestSpaces({ asks: [...] })`. The person approves it on Kovlet's approve page, without signing in again.

## 5. Files (optional)

The `main` slot already has `files: true`, and the table has an `attachment` column of type `t.fileRef()`. Upload a file and store its id on the row:

```ts title="attach.ts" hl="5,6"
import { kovlet } from "./kovlet";

export async function attach(todoId: string, file: File) {
  const main = kovlet.space("main");
  const entry = await main.files.upload(`attachments/${file.name}`, file, { mimeType: file.type });
  main.table("todos").update(todoId, { attachment: entry.id }); // store the id: it survives moves
  return main.files.url(entry.id); // a short-lived URL for <img src>
}
```

`useFiles(space, { prefix })` lists files live. `files.download()` returns a cached `Blob`, checked against its sha256. [Upload and sync files](/docs/files) covers versions, moves and the Trash.

## Next

- [Share live data between two AI-built apps](https://kovlet.com/docs/multi-app-sync): the tutorial that connects a second app to the same Data Space.
- [/llms-full.txt](https://kovlet.com/llms-full.txt): the full SDK reference (options, errors, schema evolution, quotas).
- [Node and Electron](https://kovlet.com/docs/quickstart-node), [Tauri](https://kovlet.com/docs/quickstart-tauri), [iOS](https://kovlet.com/docs/quickstart-ios) and [Android](https://kovlet.com/docs/quickstart-android) on the same space.
