10 entries · 15-question quiz
TanStack Query (React Query): Handling HTTP Requests with Ease
React ↔ Angular reference. React examples use React 19 + TypeScript with TanStack Query v5. Angular examples use modern Angular's built-in tools only (standalone components, signals, inject(), @if/@for, HttpClient services, and rxResource()/httpResource()), no third-party query library.
Test yourself
15 questions
- 1What TanStack Query Is and Setup
TanStack Query (formerly React Query) is a library for fetching, caching, and synchronizing server data. It replaces hand-written
useEffect+useStatefetching logic. - 2Fetching Data with
useQueryuseQueryruns a query function, caches its result under aqueryKey, and returns the request's state. - 3How Caching Works:
staleTimeandgcTimeTanStack Query stores every query result in the
QueryClientcache under its key, shows cached data instantly, and refetches in the background when the data is stale. - 4Dynamic Query Keys and
signalQuery keys can include variables, giving each combination its own cache entry. The
queryFnreceives anAbortSignalto cancel outdated requests. - 5Conditional Queries with
enabledenabled: falsestops a query from running automatically until a condition is met. - 6Sending Data with
useMutationuseMutationhandles requests that change data (POST, PUT, DELETE). UnlikeuseQuery, it doesn't run automatically; you trigger it withmutate(). - 7Invalidating Queries
queryClient.invalidateQueries()marks cached queries as stale and refetches the ones currently on screen, so the UI shows the latest data after a mutation. - 8Optimistic Updates
Updating the UI before the server responds, assuming success, then rolling back if the request fails.
- 9Organizing Queries and Services
Conventions that keep query keys, fetch functions, and components maintainable as the app grows.
- 10Summary