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.
On this page
What you'll build
- A todo list that stays in sync across browser tabs, devices and every other app on the same Data SpaceTyped 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.
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 athttps://kovlet.com. - Or run
kovletd --devon your machine, from theghcr.io/kovlethq/kovletdDocker image or thekovletdbinary. Run Kovlet locally starts it and shows how to approve your app from the terminal.
Step 1: Install
npm i @kovlet/client @kovlet/reactStep 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.
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
appNameis what people see when they approve your app. - Line 7
mainis a slotA 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 theeditorrole, so it can read and write. - Line 11your 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 starts both with one Docker command.
Step 3: Sync a table
Wrap your app in KovletProvider, then read the table with useTable.
React
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
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());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
todostable.
Step 4: Pick or create a spaceOptional
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:
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.
Step 5: FilesOptional
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:
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 covers versions, moves and the Trash.
Next
- Share live data between two AI-built apps: the tutorial that connects a second app to the same Data Space.
- /llms-full.txt: the full SDK reference (options, errors, schema evolution, quotas).
- Node and Electron, Tauri, iOS and Android on the same space.
Ready to try it? Start free. No credit card, no API keys.
For coding agents: this page is also Markdown. Add .md to the URL or send Accept: text/markdown. The full reference is at /llms-full.txt.