File: prefer-query-object-syntax.md | Updated: 11/15/2025
Search...
+ K
Auto
Docs Examples GitHub Contributors
Docs Examples GitHub Contributors
Docs Examples GitHub Contributors
Docs Examples Github Contributors
Docs Examples Github Contributors
Docs Examples Github Contributors
Docs Examples Github Contributors
Docs Examples Github Contributors
Maintainers Partners Support Learn StatsBETA Discord Merch Blog GitHub Ethos Brand Guide
Documentation
Framework
React
Version
v4
Search...
+ K
Menu
Getting Started
Guides & Concepts
Community Resources
API Reference
ESLint
Plugins
Examples
Framework
React
Version
v4
Menu
Getting Started
Guides & Concepts
Community Resources
API Reference
ESLint
Plugins
Examples
On this page
Copy Markdown
You can use useQuery in two different ways.
Standard
tsx
useQuery(queryKey, queryFn?, options?)
// or
useQuery(options)
useQuery(queryKey, queryFn?, options?)
// or
useQuery(options)
This rule prefers the second option, as it is more consistent with other React Query hooks, like useQueries. It will also be the only available option in a future major version.
Examples of incorrect code for this rule:
js
/* eslint "@tanstack/query/prefer-query-object-syntax": "error" */
import { useQuery } from '@tanstack/react-query';
useQuery(queryKey, queryFn, {
onSuccess,
});
useQuery(queryKey, {
queryFn,
onSuccess,
});
/* eslint "@tanstack/query/prefer-query-object-syntax": "error" */
import { useQuery } from '@tanstack/react-query';
useQuery(queryKey, queryFn, {
onSuccess,
});
useQuery(queryKey, {
queryFn,
onSuccess,
});
Examples of correct code for this rule:
js
import { useQuery } from '@tanstack/react-query';
useQuery({
queryKey,
queryFn,
onSuccess,
});
import { useQuery } from '@tanstack/react-query';
useQuery({
queryKey,
queryFn,
onSuccess,
});
When Not To Use It
------------------
If you don't care about useQuery consistency, then you will not need this rule.
This rule was initially developed by KubaJastrz in eslint-plugin-react-query .
[###### Want to Skip the Docs?
Query.gg - The Official React Query Course
\
“If you’re serious about *really* understanding React Query, there’s no better way than with query.gg”—Tanner Linsley
Learn More](https://query.gg/?s=tanstack)
You are currently reading v4 docs. Redirect to latest version?
Latest Hide
