LearnThatStack Ace your next interview
Frontend Development
React Query.
49 Qs 7 free
Change topic Change
Drill · questions

All questions

of 49
Beginner 9
01

What are the main hooks provided by React Query?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

React Query provides several core hooks:

  • useQuery: For fetching and caching data
  • useMutation: For creating, updating, or deleting data
  • useQueryClient: For accessing the query client instance
  • useInfiniteQuery: For paginated or infinite scrolling data
  • useQueries: For running multiple queries in parallel
  • useIsFetching: For getting the number of currently fetching queries
  • useIsMutating: For getting the number of currently running mutations
    The two most commonly used are useQuery for read operations and useMutation for write operations.
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

The model's verdict: “

The interactive diagram is below the answer - jump to diagram ↓

This answer is explained by a shared concept diagram - open

Tailored explanation · switch back to · ·
Point the redraw:
How well did you know this?
AI:

02

How do you set up React Query in a React application?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

Setting up React Query involves three main steps:

  1. Install the package:
npm install @tanstack/react-query
  1. Create and provide QueryClient:
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
const queryClient = new QueryClient();
function App() {
  return (
    <QueryClientProvider client={queryClient}>
      {/* Your app components */}
    </QueryClientProvider>
  );
}
  1. Use React Query hooks in components:
import { useQuery } from '@tanstack/react-query';
function Posts() {
  const { data, isLoading, error } = useQuery({
    queryKey: ['posts'],
    queryFn: () => fetch('/api/posts').then(res => res.json())
  });
  if (isLoading) return 'Loading...';
  if (error) return 'Error occurred';
  return <div>{/* Render posts */}</div>;
}
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

The model's verdict: “

The interactive diagram is below the answer - jump to diagram ↓

This answer is explained by a shared concept diagram - open

Tailored explanation · switch back to · ·
Point the redraw:
How well did you know this?
AI:

03

Explain the basic structure of a `useQuery` hook

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

The useQuery hook accepts a configuration object with key properties:

const { data, isLoading, error, isError, isSuccess } = useQuery({
  queryKey: ['posts', userId], // Unique identifier for the query
  queryFn: () => fetchPosts(userId), // Function that returns a promise
  enabled: !!userId, // Optional: conditionally enable the query
  staleTime: 5 * 60 * 1000, // Optional: how long data stays fresh
  refetchOnWindowFocus: false // Optional: disable refetch on window focus
});

Key properties:

  • queryKey: Unique identifier used for caching and invalidation
  • queryFn: Async function that fetches the data
  • enabled: Boolean to conditionally run the query
  • staleTime: Time in milliseconds before data is considered stale
    Return values:
  • data: The fetched data
  • isLoading: True during the first fetch
  • error: Error object if the query failed
  • isError/isSuccess: Boolean states for handling different scenarios
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

The model's verdict: “

The interactive diagram is below the answer - jump to diagram ↓

This answer is explained by a shared concept diagram - open

Tailored explanation · switch back to · ·
Point the redraw:
How well did you know this?
AI:

04

What is the difference between `isLoading` and `isFetching` in React Query?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

These two states serve different purposes:
isLoading:

  • True only during the first fetch when there's no cached data
  • False if there's any cached data, even if a background refetch is happening
  • Used to show initial loading states
    isFetching:
  • True whenever any fetch is happening (initial or background)
  • True during background refetches even if cached data exists
  • Used to show loading indicators for any fetching activity
const { data, isLoading, isFetching } = useQuery({
  queryKey: ['posts'],
  queryFn: fetchPosts
});
// First load: isLoading = true, isFetching = true
// Background refetch: isLoading = false, isFetching = true
// With cached data: isLoading = false, isFetching = false

This distinction allows you to show different UI states - a full loading screen for initial loads and a subtle indicator for background updates.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

The model's verdict: “

The interactive diagram is below the answer - jump to diagram ↓

This answer is explained by a shared concept diagram - open

Tailored explanation · switch back to · ·
Point the redraw:
How well did you know this?
AI:

05

How do query keys work in React Query?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

Query keys are unique identifiers that React Query uses for caching, invalidation, and refetching. They must be arrays and are compared deeply.
Basic structure:

// Simple key
queryKey: ['posts']
// Key with parameters
queryKey: ['posts', userId]
// Key with complex parameters
queryKey: ['posts', { userId, status: 'published' }]

Key principles:

  • Uniqueness: Different keys create separate cache entries
  • Hierarchy: Keys are hierarchical, allowing group operations
  • Deep comparison: React Query compares keys deeply to determine if data should be refetched
    Examples:
// These are different queries with separate cache
queryKey: ['posts'] // All posts
queryKey: ['posts', 1] // Posts for user 1
queryKey: ['posts', 2] // Posts for user 2
// Invalidation example
queryClient.invalidateQueries({ queryKey: ['posts'] }); // Invalidates all post queries
queryClient.invalidateQueries({ queryKey: ['posts', 1] }); // Only user 1's posts

Query keys enable React Query's intelligent caching and make it easy to manage related data.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

The model's verdict: “

The interactive diagram is below the answer - jump to diagram ↓

This answer is explained by a shared concept diagram - open

Tailored explanation · switch back to · ·
Point the redraw:
How well did you know this?
AI:

06

What is `useMutation` and when would you use it?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

useMutation is used for operations that create, update, or delete data (side effects). Unlike useQuery, mutations don't run automatically and must be triggered manually.
Basic usage:

const mutation = useMutation({
  mutationFn: (newPost) => fetch('/api/posts', {
    method: 'POST',
    body: JSON.stringify(newPost)
  }),
  onSuccess: (data) => {
    // Invalidate and refetch related queries
    queryClient.invalidateQueries({ queryKey: ['posts'] });
  },
  onError: (error) => {
    console.error('Failed to create post:', error);
  }
});
// Trigger the mutation
const handleSubmit = (formData) => {
  mutation.mutate(formData);
};

Key properties:

  • mutationFn: Function that performs the mutation
  • onSuccess: Callback for successful mutations
  • onError: Callback for failed mutations
  • onSettled: Callback that runs regardless of success/failure
    Use cases:
  • Creating new records
  • Updating existing data
  • Deleting records
  • Any operation that modifies server state
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

The model's verdict: “

The interactive diagram is below the answer - jump to diagram ↓

This answer is explained by a shared concept diagram - open

Tailored explanation · switch back to · ·
Point the redraw:
How well did you know this?
AI:

07

How do you handle loading and error states in React Query?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

React Query provides built-in states for handling different scenarios:
Basic approach:

const { data, isLoading, error, isError } = useQuery({
  queryKey: ['posts'],
  queryFn: fetchPosts
});
if (isLoading) return <div>Loading posts...</div>;
if (isError) return <div>Error: {error.message}</div>;
return (
  <div>
    {data.map(post => (
      <div key={post.id}>{post.title}</div>
    ))}
  </div>
);
const { data, isLoading, error, isError } = useQuery({
  queryKey: ['posts'],
  queryFn: fetchPosts,
  retry: 3, // Retry failed requests 3 times
  retryDelay: (attemptIndex) => Math.min(1000 * 2 ** attemptIndex, 30000)
});

// Custom error boundary
if (isError) {
  return (
    <div>
      <h3>Something went wrong</h3>
      <p>{error.message}</p>
      <button onClick={() => refetch()}>Try Again</button>
    </div>
  );
}

For mutations:

const mutation = useMutation({
  mutationFn: createPost,
  onError: (error, variables, context) => {
    // Handle mutation errors
    setErrorMessage(error.message);
  }
});

return (
  <div>
    <button 
      onClick={() => mutation.mutate(postData)}
      disabled={mutation.isPending}
    >
      {mutation.isPending ? 'Creating...' : 'Create Post'}
    </button>
    {mutation.isError && <div>Error: {mutation.error.message}</div>}
  </div>
);
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

The model's verdict: “

The interactive diagram is below the answer - jump to diagram ↓

This answer is explained by a shared concept diagram - open

Tailored explanation · switch back to · ·
Point the redraw:
How well did you know this?
AI:

08

What is the purpose of `staleTime` and `cacheTime` in React Query?

Part of Pro
09

How do you invalidate queries in React Query?

Part of Pro
Intermediate 18
10

Explain the concept of optimistic updates in React Query

Part of Pro
11

How do you implement dependent queries in React Query?

Part of Pro
12

What are the different ways to update query data in React Query?

Part of Pro
13

How do you implement infinite queries for pagination?

Part of Pro
14

What are React Query DevTools and how do you use them?

Part of Pro
15

How do you handle race conditions in React Query?

Part of Pro
16

How do you implement background refetching strategies?

Part of Pro
17

How do you test React Query hooks?

Part of Pro
18

What are some performance optimization techniques in React Query?

Part of Pro
19

How do you handle authentication and authorization with React Query?

Part of Pro
20

What is the `queryOptions` helper and how does it improve TypeScript support?

Part of Pro
21

How do you implement custom retry logic in TanStack Query?

Part of Pro
22

How do you handle authentication tokens with TanStack Query?

Part of Pro
23

What are the best practices for error boundaries with TanStack Query?

Part of Pro
24

How do you handle paginated data with cursor-based pagination?

Part of Pro
25

What are the differences between `useQuery` and `useSuspenseQuery`?

Part of Pro
26

What are query filters and how do you use them effectively?

Part of Pro
27

How do you handle complex data transformations in queries?

Part of Pro
Expert 22
28

How would you implement a custom query hook with complex business logic?

Part of Pro
29

How do you implement real-time updates with React Query and WebSockets?

Part of Pro
30

How would you implement a sophisticated caching strategy with multiple cache layers?

Part of Pro
31

How do you handle complex error scenarios and implement retry strategies?

Part of Pro
32

How would you implement a type-safe React Query wrapper with advanced TypeScript features?

Part of Pro
33

How do you implement server-side rendering (SSR) with React Query?

Part of Pro
34

How do you handle query synchronization across multiple browser tabs?

Part of Pro
35

How do you implement advanced pagination patterns (cursor-based, offset-based, bidirectional)?

Part of Pro
36

How do you implement query-driven architecture patterns in large applications?

Part of Pro
37

How do you handle complex state synchronization between React Query and other state management solutions?

Part of Pro
38

What are the new features in TanStack Query v5?

Part of Pro
39

How do you handle streaming data with TanStack Query?

Part of Pro
40

What are persisted queries and how do you implement them?

Part of Pro
41

How do you implement query composition patterns?

Part of Pro
42

How do you handle real-time data updates with WebSockets?

Part of Pro
43

How do you implement advanced caching strategies?

Part of Pro
44

How do you implement query-dependent mutations?

Part of Pro
45

How do you handle offline support with TanStack Query?

Part of Pro
46

How do you implement custom mutation middlewares?

Part of Pro
47

What are the best practices for testing TanStack Query hooks?

Part of Pro
48

How do you implement request deduplication and race condition handling?

Part of Pro
49

How do you implement advanced cache management strategies?

Part of Pro

No matches

Try a different filter or search term.

Pro · $10/mo

42 of 49 React Query answers are gated.

Full answers, code samples, AI explanations - simpler, deeper, or as an interactive diagram. Cancel anytime.

  • Full answers + code
  • AI explain - simpler, deeper, or visualized
  • 1,000 AI credits / month
  • Cancel anytime

Change topic

Pick a different technology or stack. Your current topic stays put until you choose a new one.

Technologies
No technologies match “”.
Cross-cutting topics
No topics match “”.
By role
Stacks & frameworks

MEAN

MongoDB, Express, Angular, Node.js

MERN

MongoDB, Express, React, Node.js

LAMP

Linux, Apache, MySQL, PHP

Django

Python Full-Stack Development

Ruby on Rails

Convention over Configuration

JAM

JavaScript, APIs, and Markup

Serverless on AWS

Serverless Architecture on AWS

Cross-cutting topics 43 topics

Interviewers also test these - they're common to every stack, whichever one you picked above.

Flutter Mobile

Flutter Cross-Platform Mobile Development

Cross-cutting topics 44 topics

Interviewers also test these - they're common to every stack, whichever one you picked above.

Spring Boot

Enterprise Java Development

.NET

Microsoft Ecosystem

Vue

Vue.js, Vite, TypeScript, Tailwind, Node.js

Go Backend

Golang, gRPC, PostgreSQL, Redis, RabbitMQ

FastAPI

Python, FastAPI, SQLAlchemy, PostgreSQL

React Native

React, TypeScript, Redux, Firebase

iOS Native

Swift, SwiftUI, UIKit, Firebase

Android Native

Java, Jetpack Compose, Firebase

Web3 / Ethereum

Solidity, Ethereum, Hardhat, Foundry

DevOps / Platform

Docker, Kubernetes, Terraform, CI/CD

Core SWE Interview Prep

Data structures, algorithms, OS, concurrency, networking, git
Big-O & Complexity Analysis Arrays, Strings & Hash Tables Linked Lists, Stacks & Queues Trees, BSTs & Heaps Graphs Sorting, Searching & Recursion Operating Systems Concurrency & Multithreading Networking for Developers Git & Version Control API Design 45 Distributed Systems Fundamentals 34

Cross-cutting topics 43 topics

Interviewers also test these - they're common to every stack, whichever one you picked above.


Cross-cutting topics 45 topics

Interviewers also test these - they're common to every stack, whichever one you picked above.