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
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
