Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

no-void-query-fn.md

41 lines999 Bytes

1---
2id: no-void-query-fn
3title: Disallow returning void from query functions
4---
5​
6Query functions must return a value that will be cached by TanStack Query. Functions that don't return a value (void functions) can lead to unexpected behavior and might indicate a mistake in the implementation.
7​
8## Rule Details
9​
10Example of **incorrect** code for this rule:
11​
12```tsx
13/* eslint "@tanstack/query/no-void-query-fn": "error" */
14​
15useQuery({
16 queryKey: ['todos'],
17 queryFn: async () => {
18 await api.todos.fetch() // Function doesn't return the fetched data
19 },
20})
21```
22​
23Example of **correct** code for this rule:
24​
25```tsx
26/* eslint "@tanstack/query/no-void-query-fn": "error" */
27useQuery({
28 queryKey: ['todos'],
29 queryFn: async () => {
30 const todos = await api.todos.fetch()
31 return todos
32 },
33})
34```
35​
36The rule requires [typed linting](https://typescript-eslint.io/getting-started/typed-linting/) and does not report anything without it.
37​
38## Attributes
39​
40- [x] βœ… Recommended
41- [ ] πŸ”§ Fixable