snapshot of https://github.com/TanStack/query.git (main, 2026-09-16; blobs > 131072B omitted)
This commit is contained in:
39
docs/eslint/no-void-query-fn.md
Normal file
39
docs/eslint/no-void-query-fn.md
Normal file
@@ -0,0 +1,39 @@
|
||||
---
|
||||
id: no-void-query-fn
|
||||
title: Disallow returning void from query functions
|
||||
---
|
||||
|
||||
Query 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.
|
||||
|
||||
## Rule Details
|
||||
|
||||
Example of **incorrect** code for this rule:
|
||||
|
||||
```tsx
|
||||
/* eslint "@tanstack/query/no-void-query-fn": "error" */
|
||||
|
||||
useQuery({
|
||||
queryKey: ['todos'],
|
||||
queryFn: async () => {
|
||||
await api.todos.fetch() // Function doesn't return the fetched data
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
Example of **correct** code for this rule:
|
||||
|
||||
```tsx
|
||||
/* eslint "@tanstack/query/no-void-query-fn": "error" */
|
||||
useQuery({
|
||||
queryKey: ['todos'],
|
||||
queryFn: async () => {
|
||||
const todos = await api.todos.fetch()
|
||||
return todos
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
## Attributes
|
||||
|
||||
- [x] ✅ Recommended
|
||||
- [ ] 🔧 Fixable
|
||||
Reference in New Issue
Block a user