Installation
The plugin is a separate package that you need to install:Flat Config (eslint.config.js)
Recommended Setup
To enable all of the recommended rules for our plugin, add the following config:eslint.config.js
Custom Setup
Alternatively, you can load the plugin and configure only the rules you want to use:eslint.config.js
Legacy Config (.eslintrc)
Recommended Setup
To enable all of the recommended rules for our plugin, addplugin:@tanstack/query/recommended in extends:
.eslintrc
Custom Setup
Alternatively, add@tanstack/query to the plugins section, and configure the rules you want to use:
.eslintrc
Available Rules
The ESLint plugin includes the following rules:exhaustive-deps
Ensures all variables used in queryFn are included in the query key
no-rest-destructuring
Prevents rest destructuring in query results to maintain render optimization
stable-query-client
Ensures QueryClient is created outside of component render
no-unstable-deps
Prevents unstable values in query keys that could cause infinite loops
infinite-query-property-order
Enforces correct property order for infinite queries
no-void-query-fn
Ensures query functions return a value, not void
mutation-property-order
Enforces consistent property order in mutation options
Rule Attributes
Rules may have the following attributes:- ✅ Recommended: Enabled in the
recommendedconfiguration - 🔧 Fixable: Can be automatically fixed with
eslint --fix
Why Use the ESLint Plugin?
The ESLint plugin helps you avoid common pitfalls:1. Query Key Consistency
One of the most common mistakes is forgetting to include all variables in the query key:2. QueryClient Stability
Creating a new QueryClient on every render is a common mistake:3. Render Optimization
The plugin helps maintain TanStack Query’s smart render optimization by preventing patterns that break it.Configuration Tips
Start with the recommended configuration and adjust rules based on your team’s needs. The recommended config represents battle-tested best practices.
Adjusting Rule Severity
You can adjust the severity of any rule:Disabling Rules
If you need to disable a rule for a specific line:Migration from v4
If you’re upgrading from TanStack Query v4:- The
prefer-query-object-syntaxrule has been removed (object syntax is now required) - All other rules remain compatible
Next Steps
Exhaustive Deps Rule
Learn about the exhaustive-deps rule in detail
Stable Query Client Rule
Understand the stable-query-client rule