State Management · Middle · Question 33 of 75

Why should every variable the queryFn uses be part of the queryKey?

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.

Further reading

Problem with a question

State Management · Middle · question 33

Test yourself

Take the State Management · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz