Skip to main content
Kweri supports two React usage patterns. If your backend has an OpenAPI spec, use path-based hooks with generated types. If you’re defining endpoints manually, use useQuery and useMutation directly.
After running kweri-gen, bind hooks to the generated EndpointByMethod map. You get fully-typed useGet, usePost, usePut, usePatch, and useDelete hooks without writing any endpoint definitions yourself.

Setup

Create the hook factory once and export it. Don’t call createReactPathHooks inside a component.
Passing useSyncExternalStore on its own still works. Adding useRef gives each mutation hook call its own status; without it, components mutating the same endpoint share one status.

useGet

Mutation hooks

Full CRUD example

Path hooks resolve the endpoint schema at call time. If the path isn’t in the generated map, they throw [kweri] No endpoint registered for GET /unknown-path.

Without code generation

Use useQuery and useMutation when you’re defining endpoints manually with defineEndpoint.

Setup

Create the hooks once and export them. Don’t call createReactQueryHooks inside a component.

useQuery

ReactQueryOptions

Hooks sharing an endpoint, params and options share one subscription, so a query is issued once per mount rather than once per render — passing a fresh params object each render is fine, since keys are derived from the serialized params.

ReactQueryResult

Example

Conditional fetching


useMutation

ReactMutationResult

Example