Getting started
Quickstart
Build a collaborative to-do list that syncs across tabs in under five minutes.
On this page
In this guide you’ll build a to-do list where every change appears instantly in every open tab and keeps working when you go offline.
-
Create the client
Point the client at the project you created during installation.
src/syndra.ts import { createClient } from "@syndra/client" export const syndra = createClient({ project: import.meta.env.SYNDRA_PROJECT, publicKey: import.meta.env.SYNDRA_PUBLIC_KEY, }) -
Define a document
Documents are typed JSON trees. Give yours a schema and a default value.
src/todos.ts import { syndra } from "./syndra" type Todo = { id: string; text: string; done: boolean } export const todos = syndra.doc<{ items: Todo[] }>("lists/groceries", { initial: { items: [] }, }) -
Subscribe and render
subscribefires immediately with the local state, then again on every change local or remote.src/main.ts import { todos } from "./todos" todos.subscribe(({ items }) => { list.replaceChildren(...items.map(renderItem)) }) -
Make changes
Mutate the draft inside
update. Syndra records the change as a set of operations and syncs them.ts function addTodo(text: string) { todos.update((draft) => { draft.items.push({ id: crypto.randomUUID(), text, done: false }) }) } -
Open a second tab
Run your dev server and open the app in two windows. Add an item in one it appears in the other before you can blink. 🎉
Next steps
- Show who else is looking at the list with Presence.
- Lock the list down to signed-in users with Authentication.
- Learn how edits merge in Conflict resolution.