Do TanStack Query results need a second store?
Components using the same query key and QueryClient share cached server state. Copying the result into another store creates another value to keep synchronized.
Include data-changing filters in the key. This example uses TanStack React Query 5.90.3 and a 30-second staleTime; shared client state still needs its own owner.
Understand it. Then fix it.
Read the cache where you need it.
Usually, no. Components using the same query key and QueryClient share the cached result. A second copy creates another place you must keep synchronized.
useQuery({
queryKey: ["products"],
queryFn: () => getProducts(),
staleTime: 30_000
});A key identifies the requested data.
Two readers use this same key. Thirty thousand means thirty seconds of freshness. Filters that change the fetched data must also be part of the key.
useQuery({
queryKey: ["products", category],
queryFn: () => getProducts(category)
});A local draft is different.
Your unfinished search text can stay in useState. It is user input, not a second copy of the server's products.
const [draft, setDraft] =
useState("");A store can still earn its place.
Use a client store for genuinely shared client state, like an editor's tool selection. Query handles server synchronization; it does not replace every kind of state.
Code blocks are teaching excerpts. Keep the surrounding error handling and application requirements.
Save the code excerpts ↓Read the full transcript
TanStack Query already has my products. Do I need to copy them into a global store? The database apparently needs a roommate. Usually, no. Components using the same query key and QueryClient share the cached result. A second copy creates another place you must keep synchronized. Two readers use this same key. Thirty thousand means thirty seconds of freshness. Filters that change the fetched data must also be part of the key. Your unfinished search text can stay in useState. It is user input, not a second copy of the server's products. Use a client store for genuinely shared client state, like an editor's tool selection. Query handles server synchronization; it does not replace every kind of state. I copied the cache for convenience. Now both copies disagree professionally.