Immer vs Immutable.js
Which should you use? A side-by-side look at what each one does, who it suits, what it costs, how hard it is to set up, and where each falls short.
Open source · MIT
A JavaScript library that lets you update immutable state by writing ordinary mutating code.
Open source · MIT
JavaScript libraries for immutable data collections that never change once created.
The short answer
Choose Immer if you need…
- JavaScript developers who find hand-written immutable updates verbose or error-prone
- Teams managing nested state in Redux-style reducers
- Developers who want immutable data without learning a new state model
Choose Immutable.js if you need…
- JavaScript developers managing application state that is updated often
- Teams building React or Flux-style apps where data flows one way
- Developers who want cheap equality checks and memoization based on data changes
- TypeScript users who want type definitions included with the package
Side-by-side
| Immer | Immutable.js | |
|---|---|---|
| Type | Library | Library |
| Price | Free and open source | Free and open source |
| Licence | MIT | MIT |
| GitHub stars | 29k | 33k |
| Setup difficulty | Beginner | Intermediate |
| How you get it | Install with a package manager | Install with a package manager |
| Main language | JavaScript | TypeScript |
| Last code update | 5 days ago | 5 days ago |
What each one is
Immer
Immer is a JavaScript library for managing state without changing it directly. You write code that looks like it modifies a draft of your data, and Immer produces a new immutable copy with only the changed parts updated. The README describes it as a way to create the next immutable state tree by simply modifying the current tree. The README excerpt provided does not describe its APIs in detail, so this summary is limited to its stated purpose and topics such as Redux and reducers.
Immutable.js
Immutable.js is a JavaScript library that provides data structures such as List, Map, Set and Record that cannot be changed after creation. Instead of modifying data in place, operations return new updated versions, which makes application state easier to track. It is used to make code simpler and to help detect changes efficiently.
Best for
Immer
- JavaScript developers who find hand-written immutable updates verbose or error-prone
- Teams managing nested state in Redux-style reducers
- Developers who want immutable data without learning a new state model
Immutable.js
- JavaScript developers managing application state that is updated often
- Teams building React or Flux-style apps where data flows one way
- Developers who want cheap equality checks and memoization based on data changes
- TypeScript users who want type definitions included with the package
Strengths
Immer
- Lets you write update code in a mutating style while keeping state immutable
- Has a documentation site linked from the README
- Open source under the MIT license with an active project history
Immutable.js
- Has no dependencies, according to the README
- Includes type definitions for Flow and TypeScript when installed via npm
- Uses structural sharing so updates reuse most of the existing data structure
Not ideal for
Immer
- Projects that do not use JavaScript or TypeScript, since this is a JavaScript library
- Developers looking for a full state management framework, since the README presents Immer as a focused library for producing new state
Immutable.js
- Projects that only need simple data and do not care about accidental mutation, since the library adds an API to learn
- Developers who need native JavaScript arrays and objects to interoperate directly without conversion, since Immutable collections are a different type
- Beginners new to JavaScript who should first learn plain objects and arrays
Trade-offs
Immer
- The README excerpt gives little detail on API usage or limits, so evaluation requires the full documentation
- Immutable-update libraries add a dependency and a new pattern for teams to learn
Immutable.js
- Requires learning a new API and treating collections as values rather than objects
- TypeScript type definitions need ES2015 lib or target settings, per the README
- Converting between Immutable collections and plain JavaScript data adds work at boundaries
Getting started
Immutable.js
Install using npm
npm install immutableInstall using Yarn
yarn add immutableFrequently asked questions
What is the difference between Immer and Immutable.js?
Immer: A JavaScript library that lets you update immutable state by writing ordinary mutating code. Immutable.js: JavaScript libraries for immutable data collections that never change once created. Immer suits javascript developers who find hand-written immutable updates verbose or error-prone, while Immutable.js suits javascript developers managing application state that is updated often.
Are Immer and Immutable.js free?
Immer: Free and open source. Immutable.js: Free and open source.
Which is easier to set up, Immer or Immutable.js?
Immer is easier to get started with (rated beginner); Immutable.js is rated intermediate and usually needs more setup.
Is Immer or Immutable.js more popular?
Immutable.js has more GitHub stars (33k) than Immer (29k). Popularity isn't the same as fit — check which one matches your use case above.
What are other alternatives to Immer and Immutable.js?
Other options people compare them with include Redux Toolkit, UI-Router.
Keep comparing
Built from our catalogue entries for both products: open-source details come from each project's README (AI-assisted, refreshed weekly) and GitHub data; AI-tool details are editorial. Spotted something wrong? Let us know from either product's page.