Web / TanStack Interview Questions
What are the most common TanStack Query mistakes in Vue and how do you avoid them?
Knowing what not to do is as important as knowing the API. These patterns trip up most developers new to TanStack Query in Vue.
| Mistake | Problem | Fix |
|---|---|---|
| queryKey not including all query variables | Stale data served when variable changes | Add every queryFn variable to the key |
| Non-reactive queryKey in Vue | Query doesn't re-run when props change | Wrap queryKey in computed() when it reads reactive state |
| Server state in both TanStack Query and Pinia | Two sources of truth — sync bugs | Use TanStack Query as the single source for server data |
| New QueryClient per component | Each component gets its own empty cache | Create QueryClient once in main.ts |
| staleTime=0 for slow/static data | Unnecessary refetch on every window focus | Set staleTime to match data update frequency |
// WRONG: non-reactive key â captured once at setup, never updates const { data }=useQuery({ queryKey: ["user", props.userId], // plain read, not reactive queryFn: ()=>fetchUser(props.userId), }) // CORRECT: reactive via computed() const { data }=useQuery({ queryKey: computed(()=>["user", props.userId]), queryFn: ()=>fetchUser(props.userId), }) // WRONG: duplicating server state into Pinia const { data:user }=useQuery({ queryKey: ["user",1], queryFn: fetchUser, onSuccess: u=>userStore.setUser(u), // unnecessary sync â two sources of truth }) // CORRECT: read data directly from useQuery wherever needed
More Related questions...