Web / TanStack Interview Questions
What are the status and fetchStatus values in TanStack Query v5 and how do they drive UI?
v5 separates state into two orthogonal dimensions: status (what does the cache contain?) and fetchStatus (is a network request happening?). Understanding both prevents wrong loading UI.
| status | fetchStatus | Meaning |
|---|---|---|
| pending | fetching | No data yet, first load — show full-page spinner |
| pending | idle | enabled=false — query paused, will never fetch |
| success | fetching | Has data, refetching in background — show subtle indicator |
| success | idle | Has fresh data, nothing happening — steady state |
| error | idle | All retries exhausted — show error UI |
<script setup lang="ts">
import { useQuery } from "@tanstack/vue-query"
const {
data, isPending, isSuccess, isError,
isFetching, // fetchStatus==="fetching"
isLoading, // isPending && isFetching — true ONLY on first load
error,
}=useQuery({ queryKey:["posts"], queryFn:fetchPosts })
</script>
<template>
<LoadingSpinner v-if="isLoading" />
<ErrorMessage v-else-if="isError" :msg="error.message" />
<div v-else>
<RefetchBadge v-if="isFetching" />
<PostList :posts="data" />
</div>
</template>
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...
