Framework Patterns
Look up the matching Jazz API in React and Expo, Vue, Svelte and Solid.Jazz provides framework-specific bindings for React/Expo, Vue, Svelte, and Solid. This page is a side-by-side reference — see Reading Data, Writing Data, and How Auth Works for full details.
API equivalents
| Concept | React / Expo | Vue | Svelte | Solid |
|---|---|---|---|---|
| Provider | <JazzProvider> | <JazzProvider> | <JazzProvider> | <JazzProvider> |
| Jazz session | useJazzSession() | useJazzSession() | getJazzSession() | useJazzSession() |
| Query subscription | useAll(query) | useAll(query) | new QuerySubscription(query) | useAll(() => ({ query })) |
| Single-row query | useOne(query) | useOne(query) | new QuerySubscriptionOne(query) | useOne(() => ({ query })) |
| DB access | useAll(query).db | useAll(query).db | subscription.db | useAll(...).db |
| Write-only DB | useDb() | useDb() | getDb() | useDb() |
| Client without UI | createJazzClient(config) | createJazzClient(config) | createJazzClient(config) | createJazzClient(config) |
Provider setup
Wrap your app in <JazzProvider config={…}>. config takes the same options as
createJazzClient (serverUrl, client, initial and the rest; see
Thin Client). The provider shows its signedOut view while no
one is signed in, loading while Jazz starts or switches users, and error when there is no usable
client. Once its session is closed (session.close()), it shows its closed view: nothing unless
you give one. A closed session never starts again: give the provider a new session, or a new key
for its config. useJazzSession() (Svelte: getJazzSession()) reads the session anywhere below, including
in those views.
The error view receives the same { error, recovery, retry } in every framework: as a function's
argument in React, React Native and Solid, as slot props in Vue, and as a snippet's argument in
Svelte. recovery says what retry() does: repeat the operation that failed ("action") or
reopen the signed-in account ("session"). This retry() never rejects: a new failure shows in
the error view again, so you can hand it straight to a button.
App.tsximport { JazzProvider } from "jazz-tools/react";export function Root() {return (<JazzProviderconfig={{ serverUrl: "/jazz", client: () => import("jazz-tools/local-first") }}signedOut={<SignIn />}loading={<p>Loading…</p>}error={({ error, retry }) => <button onClick={retry}>{error.message}: retry</button>}><App /></JazzProvider>);}
App.vue<script setup lang="ts">import { JazzProvider, type JazzClientConfig } from "jazz-tools/vue";const config: JazzClientConfig = {serverUrl: "/jazz",client: () => import("jazz-tools/local-first"),};</script><template><JazzProvider :config="config"><TodoApp /><template #signedOut><SignIn /></template><template #loading><p>Loading…</p></template><template #error="{ error, retry }"><button @click="retry">{{ error.message }}: retry</button></template></JazzProvider></template>
App.svelte<script lang="ts">import { JazzProvider } from "jazz-tools/svelte";</script><JazzProvider config={{ serverUrl: "/jazz", client: () => import("jazz-tools/local-first") }}><TodoApp />{#snippet signedOut()}<SignIn />{/snippet}{#snippet loading()}<p>Loading…</p>{/snippet}{#snippet error({ error, retry })}<button onclick={retry}>{error.message}: retry</button>{/snippet}</JazzProvider>
Call getDb(), getJazzSession() and the other get… helpers during component setup (the
top level of a component's <script>), not later in an event handler: they read Svelte
context. Stores and utility modules can't, so pass them the db from there.
In SvelteKit, render the provider only in the browser ({#if browser} from $app/environment)
and load server-rendered data in +page.server.ts with
jazz.forReqUser. For production builds,
add ssr: { external: ["jazz-napi"] } to vite.config.ts so Vite doesn't bundle Jazz's native
module. Behind a proxy that terminates TLS, set adapter-node's PROTOCOL_HEADER (for example
x-forwarded-proto), or Jazz sees http:// and refuses sign-in as an origin it doesn't allow.
App.tsximport { JazzProvider } from "jazz-tools/solid";export function Root() {return (<JazzProviderconfig={{ serverUrl: "/jazz", client: () => import("jazz-tools/local-first") }}signedOut={<SignIn />}loading={<p>Loading…</p>}error={({ error, retry }) => <button onClick={retry}>{error.message}: retry</button>}><App /></JazzProvider>);}
Leave out client for a thin client. The provider creates its session when it mounts and closes it
when it unmounts; use a key to replace it with a new config. To show a session you opened yourself
with createJazzClient (or startJazzClient, which returns it while it starts), pass
session={session} instead of config; the provider then leaves closing it to you.
Query subscriptions
Subscribe to query results reactively. See Reading Data for the full API.
App.tsxexport function LiveQueryExample() {const { data: todos, isLoading, error } = useAll(app.todos.where({ done: false }));if (isLoading) return <p>Loading...</p>;if (error) return <p>Something went wrong!</p>;return (<ul>{todos.map((todo) => (<li key={todo.id}>{todo.title}</li>))}</ul>);}
App.vue<script setup lang="ts">import { useAll } from "jazz-tools/vue";import { app } from "../jazz.generated.js";const { data: todos } = useAll(app.todos.where({ done: false }));</script><template><li v-for="todo in todos ?? []" :key="todo.id">{{ todo.title }}</li></template>
App.svelte<script lang="ts">import { QuerySubscription } from 'jazz-tools/svelte';import { app } from '../jazz.generated.js';const todos = new QuerySubscription(app.todos.where({ done: false }),);</script>{#each todos.current ?? [] as todo}<li>{todo.title}</li>{/each}
App.tsximport { For } from "solid-js";import { useAll } from "jazz-tools/solid";import { app } from "../jazz.generated.js";export function QuerySubscriptionExample() {const todos = useAll(() => ({ query: app.todos.where({ done: false }) }));return <For each={todos.data ?? []}>{(todo) => <li>{todo.title}</li>}</For>;}
The ?? [] guard handles the undefined (not yet connected) case. See
Reading data: the loading state for patterns that depend on this signal.
In Vue, Svelte, and Solid, the binding reconciles updates into the existing reactive array in place, so only fields that actually changed trigger re-renders. See Fine-grained updates for the full behaviour.
Accessing the database for writes
Get a handle to the database for inserts, updates, and deletes. See Writing Data for the full API.
App.tsxexport function DbAccessExample() {// Must be called at component top level (rules of hooks)const db = useDb();async function addTodo(title: string) {await db.insert(app.todos, { title, done: false });}void addTodo;return null;}
DbSessionExamples.vue// Must be called inside setup() or <script setup>const db = useDb();async function addTodo(title: string) {await db.insert(app.todos, { title, done: false });}
DbSessionExamples.svelte// During component setup: getDb() reads Svelte context.const db = getDb();async function addTodo(title: string) {await db.insert(app.todos, { title, done: false });}// Stores and utility modules can't read context: pass them the db from here.function createTodoActions(database: Db) {return {complete: (id: string) => database.update(app.todos, id, { done: true }),};}const todoActions = createTodoActions(db);
DbSessionExamples.tsximport { useDb, useJazzSession } from "jazz-tools/solid";import { app } from "../jazz.generated.js";export function DbSessionExamples() {const db = useDb();// Who is signed in: { accountId, kind: "device" | "backend", identity, claims } | null.// Your permissions see the same user as `session.user` (the accountId),// `session.identity` and `session.claims`.const { snapshot } = useJazzSession(); // snapshot().userasync function addTodo(title: string) {await db().insert(app.todos, { title, done: false });}void addTodo;void snapshot;return null;}
Session/user identity
One hook tells you who is signed in: useJazzSession() (Svelte: getJazzSession(), a store you
read as $session). Its user is { accountId, kind, identity, claims }, or null when no one is
signed in. kind is "device" for a device account (a guest) and "backend" for a user your
backend signed in. It also carries the operations: refresh(), signOut(),
createDeviceAccount() and the rest.
user is also what your permissions see: session.user in a policy is user.accountId, and
session.identity and session.claims are user.identity and user.claims. Compare a row's owner
column with user.accountId.
| Framework | Signed-in user |
|---|---|
| React / React Native | useJazzSession().user |
| Vue | useJazzSession().snapshot.value.user |
| Solid | useJazzSession().snapshot().user |
| Svelte | $session.user, with const session = getJazzSession() |
See How Auth Works for details on authentication modes and identity linking.
App.tsxexport function SessionExample() {// Who is signed in: { accountId, kind: "device" | "backend", identity, claims } | null.// Your permissions see the same user as `session.user` (the accountId),// `session.identity` and `session.claims`.const { user } = useJazzSession();void user;return null;}
DbSessionExamples.vue// Who is signed in: { accountId, kind: "device" | "backend", identity, claims } | null.// Your permissions see the same user as `session.user` (the accountId),// `session.identity` and `session.claims`.const { snapshot } = useJazzSession(); // snapshot.value.user
DbSessionExamples.svelte// Who is signed in: { accountId, kind: "device" | "backend", identity, claims } | null.// Your permissions see the same user as `session.user` (the accountId),// `session.identity` and `session.claims`.const jazzSession = getJazzSession(); // $jazzSession.user
DbSessionExamples.tsximport { useDb, useJazzSession } from "jazz-tools/solid";import { app } from "../jazz.generated.js";export function DbSessionExamples() {const db = useDb();// Who is signed in: { accountId, kind: "device" | "backend", identity, claims } | null.// Your permissions see the same user as `session.user` (the accountId),// `session.identity` and `session.claims`.const { snapshot } = useJazzSession(); // snapshot().userasync function addTodo(title: string) {await db().insert(app.todos, { title, done: false });}void addTodo;void snapshot;return null;}