State Management · Senior · Question 55 of 75
What is wrong with this cache update?
queryClient.setQueryData(["todos"], (old) => {
old.push(newTodo);
return old;
});- ✓Correct answer: It mutates cached data; return a new array, otherwise observers may not update and structural sharing breaks
- 2
setQueryDataonly accepts objects - 3It must be awaited
Explanation
Write (old) => old ? [...old, newTodo] : [newTodo]. Cached data is treated as immutable, just like React state.