本页还没有译文
本页 7 段还没译成Русский,下面显示的是英文原文。Disallow returning void from query functions
还没翻译译自英文(tanstack.com)本页 7 段都还没译
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:
/* 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:
/* eslint "@tanstack/query/no-void-query-fn": "error" */
useQuery({
queryKey: ['todos'],
queryFn: async () => {
const todos = await api.todos.fetch()
return todos
},
})Attributes
- ✅ Recommended
- 🔧 Fixable
AI 翻译查看英文原文