pkgdocs/compare/immer vs react-query

Comparing

npm

immer

Create your next immutable state by mutating the current one

41.7M/ wk
v11.1.4
vs
npm

react-query

Hooks for managing, caching and syncing asynchronous and remote data in React

1.6M/ wk
v3.39.3
Metricimmerreact-query
Ecosystemnpmnpm
DifficultyBeginnerBeginner
Weekly downloads41.7M↑1.6M
Latest versionv11.1.4v3.39.3
Recipes11

Tags

immer only

immutablestatereduxmutationsmutablecopy-on-writeimmutablesreducer

Shared

reacttypescript

react-query only

data-fetchingcachingserver-stateasynccachedatafetchgraphql

When to use each

immer

Use Immer whenever you have deeply nested state updates that are painful to write immutably: Redux reducers, Zustand's set function, or React useState with complex objects. It's built into Redux Toolkit's createSlice, so you're probably already using it.

react-query

Use React Query for any React app that fetches server data: REST APIs, GraphQL, or any async function. It replaces 95% of the useEffect+useState patterns for data fetching and adds caching, background refetching, and optimistic updates for free.

When to skip each

immer

For flat, simple state (a counter, a boolean toggle), immer's overhead isn't worth it — just spread the object. Immer also has edge cases with classes, Maps, and Sets that require using enableMapSet() and enableAllPlugins().

react-query

React Query is for server state (data that lives on a server). For UI state (modals, form values, local toggles), use useState or Zustand. If you're already using a full data layer like Apollo Client for GraphQL, React Query is redundant.

Sample recipes

immer

  • Install immer

react-query

  • Install react-query