State Management · Middle · Question 33 of 75
Why should every variable the queryFn uses be part of the queryKey?
- ✓Correct answer: Otherwise different data is cached under one key and doesn't refetch when the variable changes
- 2Because
queryFncan't access component variables - 3Because keys must have at least three elements
Explanation
The key is the cache identity, like effect dependencies. useQuery({ queryKey: ['todos'], queryFn: () => fetchTodos(filter) }) shows the old filter's results. The ESLint plugin exhaustive-deps for queries catches this.