Documentation Index
Fetch the complete documentation index at: https://confect.dev/llms.txt
Use this file to discover all available pages before exploring further.
@confect/react provides drop-in replacements for Convexβs React hooks. Each hook automatically encodes your args and decodes return values through the Effect Schemas defined in your function specs. You work with the Schema Type (decoded) values on both sidesβthe hooks handle the round-trip to Convexβs Encoded representation transparently.
Functions are referenced via refs (from confect/_generated/refs) instead of Convexβs api object. Each ref carries the args, returns, and (optionally) error schemas from the corresponding function spec, which is what enables the automatic encoding and decoding.
Setup
The React provider setup is the same as vanilla Convex.src/main.tsx
useQuery
Encodes args using the specβs args schema, passes them to Convex, and decodes the result using the specβs returns schema. Returns a QueryResult<A, E>βa tagged union with Loading, Success, and Failure variants.
Given this spec:
confect/notes.spec.ts
{} (the Type of Schema.Struct({})) as args and returns a QueryResult<readonly Notes.Doc["Type"][]>. Match it with QueryResult.match:
QueryResult also exposes the lower-level predicates QueryResult.isLoading, QueryResult.isSuccess, and QueryResult.isFailure for cases where pattern matching is awkward.
Typed errors
When the refβs spec declares anerror schema, useQuery returns QueryResult<A, E> and QueryResult.match requires an onFailure handler that receives the decoded typed error. See Error Handling for how to declare error schemas.
error schema are not surfaced as Failure. They propagate the same way they do with convex/reactβs useQuery (typically reaching the nearest error boundary).
Skipping queries
Pass"skip" instead of args to disable the query subscription. The hook returns a Loading variant whose skipped flag is true, which lets you distinguish a query that is genuinely in flight from one sitting idle because no args have been provided.
useMutation
Returns a function that encodes args using the specβs args schema, calls the Convex mutation, and decodes the result using the specβs returns schema. The returned promiseβs shape depends on whether the spec declares an error schema.
Without an error schema
The function returns Promise<A>, matching convex/reactβs useMutation. Undeclared failures still reject the promise.
confect/notes.spec.ts
With an error schema
When the spec declares an error schema, the function returns Promise<Either<A, E>>. Unwrap with Either.match (or another Either combinator) to handle both branches. Undeclared failures still reject the promise.
confect/notes.spec.ts
useAction
Same shape as useMutation: returns Promise<A> when the ref has no error schema, and Promise<Either<A, E>> when it does.
confect/random.spec.ts
Differences from vanilla Convex hooks
| Vanilla Convex | Confect |
|---|---|
Functions referenced via api.module.fn | Functions referenced via refs |
| Args passed directly to Convex as-is | Args are schema-encoded from Type to Encoded before sending to Convex |
| Return values received directly from Convex as-is | Return values are schema-decoded from Encoded to Type before returning |
useQuery returns T | undefined | useQuery returns QueryResult<A, E> |
| Cannot distinguish loading from skipped | Loading carries a skipped: boolean flag |
useMutation/useAction always return Promise<T> | Refs with an error schema return Promise<Either<A, E>>; refs without one still return Promise<A> |
Pass "skip" to disable query subscription | Sameβpass "skip" to disable query subscription |