Open History to see the last commit
1---
2id: prefer-query-object-syntax
3title: Prefer object syntax for useQuery
4---
5β
6You can use [`useQuery`](https://tanstack.com/query/v4/docs/reference/useQuery) in two different ways.
7β
8Standard
9β
10```tsx
11useQuery(queryKey, queryFn?, options?)
12β
13// or
14β
15useQuery(options)
16```
17β
18This 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.
19β
20## Rule Details
21β
22Examples of **incorrect** code for this rule:
23β
24```js
25/* eslint "@tanstack/query/prefer-query-object-syntax": "error" */
26β
27import { useQuery } from '@tanstack/react-query';
28β
29useQuery(queryKey, queryFn, {
30 onSuccess,
31});
32β
33useQuery(queryKey, {
34 queryFn,
35 onSuccess,
36});
37```
38β
39Examples of **correct** code for this rule:
40β
41```js
42import { useQuery } from '@tanstack/react-query';
43β
44useQuery({
45 queryKey,
46 queryFn,
47 onSuccess,
48});
49```
50β
51## When Not To Use It
52β
53If you don't care about useQuery consistency, then you will not need this rule.
54β
55## Attributes
56β
57- [x] β
Recommended
58- [x] π§ Fixable
59β
60## Credits
61β
62This rule was initially developed by [KubaJastrz](https://github.com/KubaJastrz) in [eslint-plugin-react-query](https://github.com/KubaJastrz/eslint-plugin-react-query).