Redux Toolkit slice code compared with a React Query useQuery hook

React Query vs Redux is one of the most searched comparisons in the React ecosystem, yet the two libraries solve different problems. Redux manages application state that lives in the browser, while TanStack Query manages server state that lives in a database and is only borrowed by the interface.

Understanding that split helps you pick the right tool, remove unnecessary code, or combine both in a single project. This article compares their goals, the code each requires and the situations where one clearly fits better.

Server State and Client State

Client state belongs entirely to the browser, such as an open modal, a selected tab or a multi-step form draft. Server state is owned elsewhere, can be changed by other users and becomes outdated over time. Treating both the same way leads to complex reducers for caching problems.

Why the Difference Matters

Server data needs caching, deduplication, background updates, retries and invalidation. Redux can store the result, but those behaviors must be written by hand or added through middleware. React Query provides them by default because they are its entire purpose.

How Redux Handles Remote Data

A classic Redux approach uses an async thunk plus a slice with pending, fulfilled and rejected cases. The store keeps the list and a status field, and components select both. The pattern is explicit and predictable, but every endpoint repeats the same structure.

usersSlice.js
export const loadUsers = createAsyncThunk('users/load', fetchUsers);

const usersSlice = createSlice({
  name: 'users',
  initialState: { list: [], status: 'idle' },
  reducers: {},
  extraReducers: (builder) => {
    builder
      .addCase(loadUsers.pending, (s) => { s.status = 'loading'; })
      .addCase(loadUsers.fulfilled, (s, a) => { s.status = 'idle'; s.list = a.payload; })
      .addCase(loadUsers.rejected, (s) => { s.status = 'failed'; });
  },
});

How React Query Handles the Same Data

The equivalent React Query code is a custom hook around useQuery. Loading flags, errors, caching and refetching come from the library, so the component only declares what it needs. Any component calling the hook shares the same cached response.

useUsers.js
export function useUsers() {
  return useQuery({ queryKey: ['users'], queryFn: fetchUsers });
}

What You Gain Without Extra Code

  • Requests for the same key are deduplicated automatically.
  • Data refreshes when the window regains focus or the network reconnects.
  • Unused cache entries are garbage collected after gcTime.
  • Mutations can invalidate related queries in one line.

Side-by-Side Comparison

The table summarizes the practical differences developers notice first. Neither column is better in general; each library is optimized for its own category of state.

AspectRedux ToolkitReact Query
Main purposeGlobal client stateServer state and caching
CachingManual, or through RTK QueryBuilt in
Background refetchingManualBuilt in and configurable
Boilerplate for an endpointThunk, slice and selectorsOne hook
DevToolsRedux DevToolsReact Query DevTools
Store requiredYesNo

Where RTK Query Fits

Redux Toolkit includes RTK Query, an API layer that brings caching and invalidation into a Redux store. Teams already invested in Redux often choose it to keep a single store and a single DevTools view. React Query offers similar ideas without requiring Redux at all.

Choosing Between Them

If the application already depends heavily on Redux, RTK Query keeps the architecture consistent. A new project, or one with little global client state, usually benefits from React Query plus React context or a small store for the rest.

Using Both in One Application

Many production apps run React Query for API data and Redux for complex client workflows such as editors, undo stacks or offline drafts. The rule is simple: never copy query results into Redux. Keep each piece of data in exactly one place.

  • Server lists, details and search results stay in the query cache.
  • Interface preferences and cross-page form state stay in Redux.
  • Components read both through their own hooks.

Migrating From Redux Data Slices

Migration can happen one endpoint at a time. Replace a thunk and slice with a query hook, update the components that selected that slice, and delete the old reducer. The React Query tutorial shows the hook patterns you will reuse.

Signs a Slice Should Move

A slice is a good migration candidate when it only stores a response plus loading and error flags. If it contains business logic that runs without a server, it probably belongs in Redux.

Performance and Bundle Considerations

Both libraries are mature and well optimized, so raw speed rarely decides the choice. The bigger factor is how much code you write and maintain. Removing hand-written loading reducers, cache timestamps and refetch logic usually shrinks a codebase noticeably after adopting React Query.

Re-render behavior also differs. Redux components re-render when selected values change, while React Query components re-render when the observed query changes. Both approaches allow fine-grained subscriptions, through selectors in Redux and the select option in React Query.

Team and Learning Curve

Redux introduces actions, reducers, middleware and selectors, which take time to learn but provide a strict structure. React Query introduces keys, freshness and invalidation, which feel natural to anyone who has written fetching code by hand. New team members typically become productive with query hooks quickly.

Mixing Approaches Safely

Agree on a written rule for where each type of data lives, and add it to your contributing notes. Clear ownership prevents duplicated state, which is the main risk when two state tools share one application.

A Quick Decision Checklist

Answering a few questions about your project usually settles the choice. The goal is to keep each piece of data in the tool designed for it.

  • Most state comes from APIs: choose React Query.
  • Complex client workflows with undo or offline drafts: keep Redux for them.
  • A large existing Redux codebase: consider RTK Query for consistency.
  • A small app with little shared state: React Query plus context is often enough.

React Query vs Redux FAQ

Can React Query replace Redux completely?

In apps where Redux mainly stored API responses, yes. Apps with substantial client-only logic still benefit from a dedicated client state tool.

Is React Query faster than Redux?

Speed depends on the application. React Query often reduces network requests through caching, which can improve perceived responsiveness, but neither library is universally faster.

Does React Query work with Redux DevTools?

No. It ships its own DevTools package designed around query keys and cache states.

Conclusion

React Query vs Redux is less a competition than a division of labor. Redux organizes state your interface owns, while React Query keeps borrowed server data accurate and cached with very little code.

Audit your current store, move pure API slices to query hooks, and keep Redux for the logic that genuinely lives in the browser. Explore the caching lifecycle next to configure freshness for each resource.