Immer
Immutable state updates with a mutable draft API, producing the next immutable state without boilerplate.
Official Documentation ↗v10.1. Check the official docs for the latest API surface.Installation
npm install immerpnpm add immeryarn add immerMethods
No methods match this filter.
Immer lets you work with immutable state in a more convenient way by allowing you to mutate a temporary draft and producing the next immutable state automatically. It powers Redux Toolkit and many React state libraries.
Key Features
- Mutable drafts: Write natural mutating code, get immutable results
- Structural sharing: Unchanged data is shared, not copied
- Auto-freezing: Results are deeply frozen by default
- Curried producers: Reusable updaters for reducers
- Redux integration: Core of createSlice and produce-based reducers
Errors
The following points are quoted verbatim from the official documentation. 来源:https://immerjs.github.io/immer/ · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:50:24.519Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.
- Immer will help you to follow the immutable data paradigm by addressing these pain points: Immer will detect accidental mutations and throw an error. (https://immerjs.github.io/immer/)
FAQ
- How does Immer detect changes efficiently?
- Immer uses copy-on-write proxies. It tracks which parts of the draft you mutate and only copies the affected path, leaving unchanged branches structurally shared with the original state.
- Does Immer work with React useState?
- Yes. Pass a recipe to the updater: setState(produce(draft => { draft.count++ })). Libraries like use-immer wrap this for ergonomics with a tuple similar to useState.
- What is the performance overhead of Immer?
- Immer adds a small per-update cost for proxies and freezing, typically negligible. For hot paths with millions of operations, you can disable auto-freezing via setAutoFreeze(false).
Report a problem with this API docOpens a pre-filled issue on GitHub.