쿼리 함수에서 void 반환을 허용하지 않습니다
쿼리 함수는 TanStack Query가 캐시할 값을 반환해야 합니다. 값을 반환하지 않는 함수(void 함수)는 예기치 않은 동작을 유발할 수 있으며 구현상의 실수를 나타낼 수도 있습니다.
규칙 세부 정보
이 규칙에 대한 잘못된 코드의 예:
/* eslint "@tanstack/query/no-void-query-fn": "error" */
useQuery({
queryKey: ['todos'],
queryFn: async () => {
await api.todos.fetch() // Function doesn't return the fetched data
},
})
이 규칙에 맞는 올바른 코드의 예시:
/* eslint "@tanstack/query/no-void-query-fn": "error" */
useQuery({
queryKey: ['todos'],
queryFn: async () => {
const todos = await api.todos.fetch()
return todos
},
})
속성
- ✅ 권장
- 🔧 수정 가능