@navios/react-query API
Every public export of @navios/react-query, with signatures. This page is for looking things up; the React Query guides explain how the pieces are used. Requires @tanstack/react-query ^5.102.0.
declareClient
Client methods
Each method has two forms: pass an endpoint you already declared, or declare one inline. Inline, the endpoint options and the method's own options share one object.
Unknown keys in an inline declaration are compile errors. Options given to a method override the client's defaults.
Shared options
SurfaceOptions is accepted by all three methods. KeyOptions is its first two fields.
Query keys have the shape [...keyPrefix, method, url, ...keySuffix, 'with-response'?, 'infinite'?, inputs?], where inputs is { urlParams?, params?, data? }. Mutation keys are [...keyPrefix, method, url, ...keySuffix]. See Keys and invalidation.
Query object
QueryObject<Options, TData, TError>. args is the endpoint's call arguments; it is optional wherever the endpoint requires nothing. TError is the endpoint's typed EndpointError.
See Queries.
Infinite query settings
InfiniteQuerySettings<Options, TPage> is SurfaceOptions plus:
PageParam<Options> is the input type of the endpoint's querySchema. Each page param is merged over the call's params.
Infinite query object
InfiniteQueryObject<Options, TPage, TError, TPageParam, TData> has the same members as a query object, with these differences:
- The cached value, and so the type handled by
fetch,ensure,getDataandsetData, isInfiniteData<TPage, TPageParam>. useanduseSuspensewrapuseInfiniteQueryanduseSuspenseInfiniteQuery. Theiroptionsalso excludegetNextPageParam,getPreviousPageParamandinitialPageParam, which come from the settings.- Calling the object returns
InfiniteQueryOptionsResult. - Its keys carry an
'infinite'marker, so it never shares an entry with a plain query of the same endpoint.
See Infinite queries.
Mutation settings
MutationSettings is SurfaceOptions, plus every TanStack useMutation option except mutationFn and mutationKey (retry, scope, meta, gcTime, ...), plus:
Callbacks may return a promise. context is MutationCallbackContext<TContext>: the result of useContext merged with TanStack's { client, meta, mutationKey }. In onSuccess, onError and onSettled it also has onMutateResult.
The update function given to optimistic takes a query object and an OptimisticUpdateSpec:
See Mutations and Optimistic updates.
Mutation object
MutationObject<Options, TOnMutateResult, TData, TError, TVariables> is itself the hook.
TVariables is MutationVariables<Options>: the endpoint's call arguments, optional when the endpoint requires nothing.
withResponse and DataWithResponse
With withResponse: true, a query, infinite query page or mutation result is wrapped:
Header names are lower-cased and headers is a plain record, so the value survives dehydration and persistence. Entries declared with withResponse live under their own key, marked 'with-response'. Failures still go to the error channel.
MaybeWithResponse<TData, WithResponse> is DataWithResponse<TData> when WithResponse is true, and TData otherwise.
setHttpClient and getHttpClient
setHttpClient binds an HTTP client to a QueryClient. Every query, infinite query and mutation run through that QueryClient then uses it instead of the builder's client. Pass null to remove the binding. See SSR and prefetching.
makeQuery, makeInfiniteQuery and makeMutation
The functions behind the client methods, for use without a client instance. They take an existing endpoint only, and no client defaults are applied.
Key utilities
The key-building functions the objects above use. Prefer query.key() and mutation.mutationKey; these exist for tooling that needs the same keys without a query object.