TanStack Query — Queries, Keys and Caching — Concept Check
Questions on TanStack Query — Queries, Keys and Caching. Server data is not application state. A query library treats it as a cache of someone else's data, which is what removes the loading flags, the races and the duplicate requests.
Questions in this quiz
8 questions on TanStack Query — Queries, Keys and Caching — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A developer uses `useQuery` to fetch user data with a `staleTime` of 0. What happens when the component mounts?
- AData is refetched only once.
- BData is never refetched automatically.
- CData is refetched on every mount.
- DData is refetched based on network status.
2.You have a query with a `staleTime` of 60 seconds and a `gcTime` of 5 minutes. What happens after 3 minutes of inactivity?
- AData remains in cache but is stale.
- BData is refetched automatically.
- CData is still considered fresh.
- DData is garbage collected.
3.A component using `useQuery` shows old data even after a successful refetch. What could be the issue?
- AData was never refetched.
- BNetwork issues during refetch.
- CIncorrect query key used.
- DStale data is still shown until refetch completes.
4.Which of the following is a correct way to refetch data using TanStack Query?
- ASet `staleTime` to 0.
- BCall the function directly.
- CUse a manual trigger.
- DChange the query key.
5.A developer sets `refetchOnWindowFocus` to true. What behavior should they expect?
- AData refetches only on network change.
- BData refetches on every render.
- CData never refetches automatically.
- DData refetches when window gains focus.
6.You have parallel queries fetching different topics. What is the advantage of this approach?
- AAll queries start immediately, reducing wait time.
- BQueries are deduplicated automatically.
- CQueries execute one after another, ensuring order.
- DOnly one query runs at a time, saving bandwidth.
7.Why is it important to include all dependencies in the `queryKey`?
- ATo ensure correct cache identity and data accuracy.
- BTo reduce memory usage.
- CTo improve network performance.
- DTo avoid writing manual triggers.
8.What is the role of `enabled` in dependent queries?
- ADisables query permanently.
- BReduces query complexity.
- CPrevents execution until conditions are met.
- DEnsures query runs immediately.