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

ConceptReact / ExpoVueSvelteSolid
Provider<JazzProvider><JazzProvider><JazzProvider><JazzProvider>
Jazz sessionuseJazzSession()useJazzSession()getJazzSession()useJazzSession()
Query subscriptionuseAll(query)useAll(query)new QuerySubscription(query)useAll(() => ({ query }))
Single-row queryuseOne(query)useOne(query)new QuerySubscriptionOne(query)useOne(() => ({ query }))
DB accessuseAll(query).dbuseAll(query).dbsubscription.dbuseAll(...).db
Write-only DBuseDb()useDb()getDb()useDb()
Client without UIcreateJazzClient(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.tsx
import { JazzProvider } from "jazz-tools/react";
​
export function Root() {
return (
<JazzProvider
config={{ 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.tsx
export 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>
);
}

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.tsx
export 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;
}

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.

FrameworkSigned-in user
React / React NativeuseJazzSession().user
VueuseJazzSession().snapshot.value.user
SoliduseJazzSession().snapshot().user
Svelte$session.user, with const session = getJazzSession()

See How Auth Works for details on authentication modes and identity linking.

App.tsx
export 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;
}