Skip to main content
bijection/react holds a client’s calls in components. Every hook answers a Result, so nothing throws on render. <Bijection> replaces its descendants when you replace the connection or the auth adapter reports a change of caller. A token renewal within the same authorization keeps the subtree. Framed clients on the same connection also keep the subtree. When the caller comes from React state, render <Bijection> only when useClientAuth returns true. This withdraws the old subtree before the provider commits the new caller, even if a React Activity becomes visible in that commit. Keep the component calling useClientAuth and UI state that spans sign-ins above the caller-specific subtree.

Provide the client

Connect once, at module scope, and provide the client above every hook:
apps/main/src/client.ts
apps/main/src/main.tsx
A subtree in another frame nests a framed client: <Bijection client={client.in(branch)}>. See Frames and trials.

Watch data

apps/main/src/notes.tsx
useWatch answers undefined until the first result, then each Result as the query’s value changes. Leave out the arguments when the query declares none. It watches again when the client, the function, the arguments’ value or seen changes, so keep arguments stable: build them in render from primitive values, or with useMemo. Distinct watches catch up independently. Return related values from one query when they must share a read. See Realtime. A hook can’t be called conditionally. Pass null as the arguments to hold no watch; the hook then answers undefined:

Page a selection

usePages walks a query that takes { size, cursor } and returns ctx.page(selection, { size, cursor }):
bijection/orders.ts
apps/main/src/orders.tsx
Pass the query’s other arguments. The hook supplies size and starts with cursor: null. It follows each page’s next. A changed cursor replaces the dependent pages, and facts keeps the available prefix while the replacements load. result is undefined while a page is loading and carries the refusal if a page in the walk refuses. The deployment walks the live prefix at one held version. The continuation is end when the query returned no cursor, more when loadMore() can extend the live prefix, and limit when additional rows exist beyond the live bound. Both more and limit carry the cursor. A client can use the cursor in an explicit paging query. A live prefix holds up to 16 pages over HTTP and one page over a custom transport without prefix support. The continuation is undefined while the requested prefix is loading or refused. A change of client, query, arguments, size, seen, or caller starts a new prefix. Use useWatch for values that must share one evaluation, including a single evaluation instant for time-sensitive values.

Change data

useMutation(fn) returns a function that runs the mutation and answers its Result. pending is true while a call is in flight, and last is the last result. An unsent mutation returns Withdrawn if its provider’s connection or reported caller changes. A mutation that already reached the deployment can still return its result. Each call gets a fresh once by default. To retry an Unknown, pass the same arguments and the refusal’s once as add(args, { once }). The refusal is available from the call’s result and from last until another call settles. See Retries and read-your-writes. optimistic edits watched values while a mutation is pending and until the affected watches catch up to a successful commit. See Optimistic updates.

Read your own writes

A committed mutation’s result carries its version. After the latest mutation succeeds, pass its version as seen to read at least that state.

Authenticate

Pass an auth adapter as connect(url, { contract: "discover", token }) and feed it the provider’s state with useClientAuth. See Connect and authenticate.