Skip to main content
@pylonsync/react is the React client. The db.* namespace exposes hooks that read from a local sync replica — every component using a hook re-renders automatically when a row changes (your own mutation, a server push, a write from another tab).

Install

Initialize once

Pick any entry point that runs before your first hook (src/main.tsx, a Next.js root client provider, a top-level component effect):
In Next.js + Vercel, omit baseUrl (or pass "") so the client talks same-origin and the Next rewrite forwards /api/* to your Pylon backend.

The db.* namespace

db is the public API for apps using a single global sync engine. Every method below subscribes to or writes to the same shared replica.

db.useQuery — live list

With filtering / ordering / limits:

db.useQueryOne — single row by ID

db.useInfiniteQuery — paginated with loadMore

db.useReactiveQuery — server-side query, auto re-runs

For Convex-style server functions that the framework re-runs whenever their dependency set changes:
The server records every ctx.db.* read inside your query() handler and re-runs the handler when any of those rows mutate. See Reactive queries.

db.useMutation — server function w/ optimistic updates

The ghost row appears in db.useQuery("Message", ...) instantly; the server’s broadcast reconciles in-place. See Optimistic updates.

db.useEntity — optimistic CRUD bound to one entity

When you’d rather call insert/update/delete directly than wire a server function:
Same store + reconciliation as db.useMutation.
Requires the search plugin enabled per-entity in your schema. See Search.

db.useAggregate — live count / sum / avg / groupBy

count is "*" (or a column name for COUNT(col)); sum / avg / min / max take arrays of column names; groupBy takes an array of columns (or date-bucket specs). data is one row per group.

Sessions

useSession returns a live auth object that re-renders on sign-in, sign-out, org switch, or remote session revoke. It also exposes selectOrg, clearOrg, and refresh for multi-tenant flows.

Connection status

Presence + rooms

Multiplayer shards

For tick-driven multiplayer (games, collaborative canvases):
See Live queries → shards.

Imperative calls

For one-shot reads/writes outside the React tree (effects, event handlers, server-rendered code):
These hit the local store optimistically (where applicable) and the server in the background — the same path as the hooks.

Auth helpers

For sign-in flows that the framework owns end-to-end (cookie + storage update + session refresh), use the @pylonsync/next/auth helpers (works outside Next.js too — the auth module has no Next-specific deps despite the package path):
For long-running clients, run the session auto-refresher to keep tokens fresh:

TypeScript

For end-to-end type safety from schema → hooks, use createTypedDb with your manifest’s generated types:
Run pylon codegen client --target ts to emit Schema from your app.ts.