@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):
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
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:
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
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:
db.useMutation.
db.useSearch — live faceted search
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):Imperative calls
For one-shot reads/writes outside the React tree (effects, event handlers, server-rendered code):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):
TypeScript
For end-to-end type safety from schema → hooks, usecreateTypedDb with your manifest’s generated types:
pylon codegen client --target ts to emit Schema from your app.ts.