Immer

Create your next immutable state by mutating the current one.

Library
npm
v11.1.18
28,983 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
88 /100 Excellent
Development Activity 92
Maintenance 96
Community 64
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
90 /100 Excellent
Architecture 90
Code Quality 88
Innovation 92
Learning Curve 90

Immer is a small, zero-dependency JavaScript library that lets you write the next immutable state by mutating a temporary “draft” instead of hand-rolling spreads, Object.assign, or deep clones. It wraps your base state in an ES6 Proxy, records exactly which branches of the tree you touched inside a recipe function, and produces a new state object that shares every untouched branch with the original — giving you both natural mutation syntax and full structural-sharing immutability guarantees.

Because the API surface is a single produce(base, recipe) call (plus a curried form for reducers), Immer drops into Redux reducers, React useState/useReducer updates, and any other place immutable updates are required without changing how the surrounding code reads. Optional plugins add Map/Set support, JSON patch generation, and array-method interception, keeping the core bundle minimal for consumers who don’t need them.

What You Get

  • A single produce(base, recipe) function that returns a new immutable state from mutation-style code, plus a curried form for use directly as a Redux reducer
  • produceWithPatches, applyPatches, and patch listeners for recording and replaying granular JSON-patch-style changes (undo/redo, time travel, network sync)
  • createDraft/finishDraft for manual draft lifecycles outside the callback-based produce flow
  • Opt-in plugins — enableMapSet for native Map/Set drafting, enablePatches for patch generation, enableArrayMethods for optimized array method interception — kept out of the core bundle until enabled
  • First-class TypeScript types (Draft, WritableDraft, Immutable) that infer the mutable draft shape from your immutable state type and back again
  • current() and original() helpers to inspect in-progress drafts or the untouched base value from inside a recipe

Common Use Cases

  • Writing Redux or useReducer reducers as if directly mutating state, while Immer guarantees the returned value is a new immutable object
  • Updating deeply nested React component state (nested objects/arrays) in a single setState call without manual spreading at every level
  • Building undo/redo or collaborative-editing features on top of the patches Immer generates for every producer call
  • Simplifying form-state or normalized-store libraries that need copy-on-write semantics without hand-writing structural sharing

Under The Hood

Architecture — src/immer.ts exports the public API bound to a singleton Immer instance whose produce/produceWithPatches/createDraft/finishDraft/applyPatches methods live in src/core/immerClass.ts. Calling produce() checks isDraftable(base), opens a scope via enterScope (src/core/scope.ts), and creates a root proxy through the createProxy dispatcher, which delegates to proxyMap_/proxySet_ (src/plugins/mapset.ts) for Map/Set or to createProxyProxy (src/core/proxy.ts) for plain objects and arrays. The object/array traps in proxy.ts implement copy-on-write: get lazily creates child proxies only for properties actually read, set/deleteProperty call prepareCopy() to shallow-copy a branch the first time it’s touched and markChanged() to bubble a modified_ flag up to every ancestor. After the recipe returns, finalization walks the scope’s drafts and swaps in copy_ only where modified_ is true, leaving everything else pointing at the original base_ references (structural sharing), then optionally freezes the result and emits patches through the patches plugin if a listener was supplied.

Tech Stack — The library is authored entirely in TypeScript (src/) with zero runtime dependencies, built by tsup (tsup.config.ts) into CJS, ESM, and a legacy ESM bundle plus .d.ts declarations, as declared in package.json’s exports map. Tests run on Vitest (vitest.config.ts for source, vitest.config.build.ts to re-run the suite against the built artifacts), with a separate Flow type-check pass (yarn test:flow) for consumers still on Flow, and semantic-release drives versioned publishing from the main branch.

Code Quality — __tests__/produce.ts alone runs 844 lines of scenario coverage (curried producers, Map/Set drafting, patches, class instances, frozen input, array mutation edge cases), complemented by redux.ts for reducer-integration tests, spec_ts.ts/type-external.ts for compile-time type assertions, a dedicated flow/ suite, and both dev- and prod-mode snapshot fixters (__snapshots__, __prod_snapshots__) that pin the numeric die() error codes used in production builds. Coveralls integration tracks coverage over time, reflecting the rigor expected of a dependency this widely embedded in other libraries’ reducers.

API Design — The public surface is deliberately tiny: produce(base, recipe) is the only call most consumers ever need, with a curried variant that drops straight into useReducer/Redux without a wrapper. Escape hatches (original(), current(), no-op castDraft/castImmutable for type coercion) cover the cases where you need to read outside the draft. Plugins are opt-in via explicit enableMapSet()/enablePatches()/enableArrayMethods() calls rather than bundled by default, and the TypeScript types automatically flip an Immutable<T> state type into a mutable Draft<T> inside the recipe and back — removing a whole class of manual type-casting that other immutable-update approaches require.

Used by 52 apps in this directory

TypeScript
76%
AGPL 3.0

Abby

Developer Tools · Product Management

166

Statically typed feature flags, remote config, and A/B testing with framework-native SDKs for TypeScript teams.

View details
31
Repo Health
70
Technical
64
Dependency
Built with
TypeScript 76%
MDX 18%
Updated 1 years ago
TypeScript
56%
Other

agenta

AI Development · Developer Tools · Devops

4,788

The open-source LLMOps platform unifying prompt engineering, evaluation, and observability for teams building reliable LLM applications.

View details
91
Repo Health
77
Technical
67
Dependency
Built with
TypeScript 56%
Python 39%
Updated 5 days ago
TypeScript
72%
AGPL 3.0

APITable

Databases · Low Code Platforms

15,623

API-first collaborative spreadsheet-database platform that auto-generates REST APIs and lets teams build internal tools, CRMs, and dashboards without code.

View details
71
Repo Health
77
Technical
60
Dependency
Built with
TypeScript 72%
Java 22%
Updated 3 weeks ago
Go
55%
Apache 2.0

Authgear

Authentication

2,074

Open-source, self-hostable authentication platform with passkeys, biometric login, SSO, MFA, and GraphQL admin API — a full Auth0/Clerk/Firebase alternative for SaaS and mobile apps.

View details
88
Repo Health
81
Technical
68
Dependency
Built with
Go 55%
HTML 24%
TypeScript 18%
Updated 1 weeks ago
Go
49%
MIT

Bytebase

Devops

14,512

An open-source database CI/CD and DevSecOps platform — schema migration review, GitOps-driven changes, data masking, and access control across MySQL, PostgreSQL, Oracle, Snowflake, MongoDB, and more.

View details
92
Repo Health
73
Technical
68
Dependency
Built with
Go 49%
TypeScript 42%
Updated 4 days ago
TypeScript
99%
Apache 2.0

Codebuff

AI Code Assistants

12,842

An open-source AI coding assistant that coordinates specialized agents to edit your codebase from natural language — including Freebuff, a free, ad-supported version powered entirely by open-source models like DeepSeek and Kimi.

View details
85
Repo Health
71
Technical
67
Dependency
Built with
TypeScript 99%
Updated 4 days ago
JavaScript
90%
Other

CodeSandbox

Code Editors · Developer Tools

13,650

Instantly ready browser-based IDE that runs full npm dependency resolution and transpilation entirely client-side, with no server needed.

View details
67
Repo Health
76
Technical
62
Dependency
Built with
JavaScript 90%
Updated 3 weeks ago
TypeScript
99%
Apache 2.0

Colanode

Collaboration · Knowledge Management · Team Chat

5,152

Local-first, self-hosted workspace that combines real-time chat, Notion-style pages, and structured databases — all synced via CRDTs so you work offline without losing a keystroke.

View details
46
Repo Health
73
Technical
70
Dependency
Built with
TypeScript 99%
Updated 6 months ago
TypeScript
96%
MIT

deepseek-harness

AI Agents · AI Development · Developer Tools

237,945

An open-source, plugin-based agent harness from DeepSeek AI that runs coding and automation agents across web, desktop, CLI, and SDK surfaces.

View details
81
Repo Health
89
Technical
74
Dependency
Built with
TypeScript 96%
Updated 5 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers