LiveStore requires Node.js 18 or higher. Bun 1.2+ or pnpm are recommended for the simplest dependency setup.
Install packages
Install the core LiveStore packages along with the web adapter and React bindings.Also install the Vite devtools plugin (optional but recommended):
Configure Vite
Update your
vite.config.ts to set the worker format and add the LiveStore devtools plugin:vite.config.ts
The
worker: { format: 'es' } setting is required so that Vite bundles the
LiveStore web worker as an ES module.Create the web worker
Create When you import this file from your store setup, append
src/livestore.worker.ts. This file runs in a dedicated worker thread and manages the SQLite database.src/livestore.worker.ts
?worker to the import path so Vite treats it as a worker module.Define your schema
Create
src/livestore/schema.ts. The schema declares your events (how data changes), SQLite tables (derived state), and materializers (how events produce state).src/livestore/schema.ts
Configure the store
Create The
src/store.ts. This file creates the persisted adapter and exports a useAppStore hook that components use to access the store.src/store.ts
?worker and ?sharedworker suffixes tell Vite to bundle these imports as worker modules. makePersistedAdapter uses the Origin Private File System (OPFS) for persistent storage and automatically falls back to in-memory storage in environments where OPFS is unavailable (such as private browsing mode).Set up LiveStoreProvider
Wrap your app root with
StoreRegistryProvider inside a Suspense boundary. The registry manages store lifecycles across your component tree.src/App.tsx
Commit events and query data
Use Querying data — define a query with
useAppStore() inside any component that is a descendant of StoreRegistryProvider to commit events and run reactive queries.Committing events — call store.commit() with one or more events:src/components/AddTodo.tsx
queryDb and execute it with store.useQuery(). Queries are reactive: the component re-renders whenever the underlying data changes.src/components/TodoList.tsx
Add sync with Cloudflare (optional)
To enable real-time sync across tabs and devices, install the sync package and update your worker:src/livestore.worker.ts to wire in the sync backend:
src/livestore.worker.ts