Description
Describe the bug
When refactoring parts of the queryFn
used in useQuery
(or queryOptions
) into helper functions that involve queryClient
, exhaustive-deps
will sometimes error on the queryKey
thinking that queryClient
should be included in it. It's hard to know what's the differentiator for when exhaustive-deps
thinks queryClient
should be a dependency or not; some helper functions involving queryClient
don't trigger the error, while others do.
Your minimal, reproducible example
Steps to reproduce
- Build a
useQuery
whosequeryFn
uses aqueryClient
, e.g. in the TS Playground example, to only fetch items that aren't already cached, and individually cache them (this is related to Keys for array of items #712) - Refactor out helper functions for the (get from cache) and (individually cache) portions of the queryFn, as seen in the TS Playground example
- See the inconsistent behavior of exhaustive-deps as shown in the playground example(s)
Expected behavior
No errors asking for queryClient
to be a dep in queryKey
; or at least consistent behavior. But ideally a way to refactor out helper functions (for the sake of clean code) without errors.
How often does this bug happen?
Sometimes
Screenshots or Videos
getAlreadyCachedItems
: error

No helpers: no error

individuallyCacheItem
: no error

individuallyCacheItems
: error

Platform
- MacOS, but shouldn't be relevant
Tanstack Query adapter
None
TanStack Query version
5.81.2
TypeScript version
5.7.2
Additional context
No response