pkgdocs/compare/immer vs react-router

Comparing

npm

immer

Create your next immutable state by mutating the current one

41.7M/ wk
v11.1.4
vs
npm

react-router

Declarative client-side routing for React — maps URLs to components with nested routes, loaders, and actions.

11.0M/ wk
v7.1.1
Metricimmerreact-router
Ecosystemnpmnpm
DifficultyBeginner ✓Intermediate
Weekly downloads41.7M↑11.0M
Latest versionv11.1.4v7.1.1
Recipes13↑

Tags

immer only

immutablestatereduxmutationsmutablecopy-on-writetypescriptimmutablesreducer

Shared

react

react-router only

routingspanavigationfullstack

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-router

Any React SPA needing URL-based navigation, nested layouts (dashboard sidebar + content), data loading tied to routes, form actions, protected routes.

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-router

Next.js (use its file-based router). Remix (built on React Router but adds SSR). Very simple apps with only one or two views — a state variable suffices.

Sample recipes

immer

  • Install immer

react-router

  • Set up routing in a React app
  • Nested layouts with Outlet
  • Fetch data with a loader