All products
TanStack QueryOfficial
BitaKit plugin with one shared TanStack Query client for every plugin and the React tree.
bitakit · Plugin for every BitaKit app
- Type
- Package
- Needs a build
- Kind
- Plugin
- BitaKit
- Works with
- Any app
- Every BitaKit app
- Versions
- 2
- versions
- Publisher
- bitakit
- Official
Preview
1 picture

About
@bitakit/query
One shared TanStack Query client for a BitaKit app. Services read
and write through it, and React components use the standard useQuery / useMutation hooks on
the same cache. Integrations such as @bitakit/strapi cache their reads here.
npm install @bitakit/query @tanstack/react-query
With discovery, installing the package is enough: the plugin registers the query-client
service and wraps the React tree in QueryClientProvider. Defaults go in an optional
src/configs/query.ts:
// src/configs/query.ts
export default { defaultOptions: { queries: { staleTime: 30_000 } } };
Configuration is plain data, so callbacks such as a retry function belong to the individual
queries.
In services and Actions
import { defineService, getService } from '@bitakit/core';
import { queryClient } from '@bitakit/query';
export default defineService(
({ services }) => {
const { client } = getService(services, queryClient);
return {
stats: () => client.fetchQuery({ queryKey: ['stats'], queryFn: loadStats }),
};
},
{ requires: [queryClient] },
);
In React
import { useQuery } from '@tanstack/react-query';
const { data } = useQuery({ queryKey: ['stats'], queryFn: loadStats }); // same cache as the service
Without discovery
The root entry is headless (no React):
import { createRuntime } from '@bitakit/core';
import { queryPlugin } from '@bitakit/query';
const runtime = createRuntime({ plugins: [queryPlugin({ defaultOptions: {} })] });
Notes
- The client is created with the plugin, not by the service, so the React provider renders it before the runtime is ready. The service mounts it (focus and online refetching) on start and unmounts it on stop.
@tanstack/query-coreand@tanstack/react-queryare peer dependencies: the app and every plugin share one installed copy, whichuseQueryneeds to find the provider.- A plugin that keeps per-user data in the cache removes it when the user changes; the
@bitakit/strapiauth service does this for its reads.
Information
- Publisher
- bitakit · Official
- Type
- PackageNeeds installation: add it to the app's code and build the app.
- Kind
- Plugin
- Works with
- Every BitaKit app
- npm package
- @bitakit/query (opens in a new tab)