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

  1. 1
    What 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 + useState fetching logic.

  2. 2
    Fetching Data with useQuery

    useQuery runs a query function, caches its result under a queryKey, and returns the request's state.

  3. 3
    How Caching Works: staleTime and gcTime

    TanStack Query stores every query result in the QueryClient cache under its key, shows cached data instantly, and refetches in the background when the data is stale.

  4. 4
    Dynamic Query Keys and signal

    Query keys can include variables, giving each combination its own cache entry. The queryFn receives an AbortSignal to cancel outdated requests.

  5. 5
    Conditional Queries with enabled

    enabled: false stops a query from running automatically until a condition is met.

  6. 6
    Sending Data with useMutation

    useMutation handles requests that change data (POST, PUT, DELETE). Unlike useQuery, it doesn't run automatically; you trigger it with mutate().

  7. 7
    Invalidating 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.

  8. 8
    Optimistic Updates

    Updating the UI before the server responds, assuming success, then rolling back if the request fails.

  9. 9
    Organizing Queries and Services

    Conventions that keep query keys, fetch functions, and components maintainable as the app grows.

  10. 10
    Summary