ESLint Plugin React Query

raw JSON →
1.3.0 verified Sat Apr 25 auth: no javascript maintenance

Community ESLint plugin enforcing best practices for React Query (TanStack Query) v3+. Current version 1.3.0, released February 2022, with slow release cadence. Adds rules for useQuery object syntax, missing queryKey, and mutationKey. Differentiator: lightweight, dedicated linting for React Query patterns, complementary to the official plugin. Alternative to @tanstack/eslint-plugin-query which is more maintained.

error ESLint couldn't find the plugin "eslint-plugin-react-query".
cause Plugin not installed or missing from package.json devDependencies.
fix
Run: npm install --save-dev eslint-plugin-react-query
error Definition for rule 'react-query/rule-name' was not found.
cause Typo in rule name or rule not yet implemented.
fix
Check supported rules in README: mutation-key, prefer-query-object-syntax, query-key.
breaking Plugin is not actively maintained; for TanStack Query v4+, consider using @tanstack/eslint-plugin-query.
fix Switch to @tanstack/eslint-plugin-query for official support.
deprecated prefer-query-object-syntax rule is fixable but may conflict with other patterns.
fix Use object syntax for useQuery to avoid warnings.
gotcha Rules only cover useQuery and useMutation; useInfiniteQuery and other hooks are not validated.
fix Manually enforce keys for other hooks or use other lint rules.
npm install eslint-plugin-react-query
yarn add eslint-plugin-react-query
pnpm add eslint-plugin-react-query

Set up ESLint with react-query plugin rules including object syntax enforcement.

// .eslintrc.js
module.exports = {
  plugins: ['react-query'],
  extends: ['plugin:react-query/recommended'],
  rules: {
    'react-query/prefer-query-object-syntax': 'warn',
  },
};

// Example code that triggers rule:
// useQuery('key', fetchSomething) // no object syntax -> warning
// useQuery({ queryKey: 'key', queryFn: fetchSomething }) // ok