Mutative lets you update immutable state by mutating a draft object, similar in style to Immer. It targets Redux-style reducers with optional patches, freezing, and marks for custom types.
Overview
Mutative is a JavaScript library for producing the next immutable state after you write ordinary-looking mutations against a draft. It is aimed at state management in Redux and other immutable stores, with an API centered on create and producer-style reducers.
The implementation copies each object at most once per update, drafts only when recipes read values, and runs native array methods on its copies. Optional auto-freeze, JSON Patch style patches, strict mode, async recipes, and Map or Set subclass support are built in rather than requiring separate plugins.
Published benchmarks in the project documentation compare timing against Immer and hand-written spread reducers across many workloads, especially large arrays and wide objects. Ecosystem packages connect Mutative to React, Zustand, Jotai, XState, and Yjs, and a compatibility layer mirrors common Immer APIs.
Documentation describes migration from Immer, marks for class instances, custom shallow copy hooks, and reducer patterns. The library ships as an npm package installable with npm install mutative.
Key features
- Draft-based immutable updates
- Optional JSON Patch generation
- Per-call options without global plugins
- Map, Set, and class instance drafts
- Async recipe support
- Strict mode for non-draft reads
- Redux-compatible producers
- mutative-compat Immer API layer
Use cases
- Redux reducers without manual spreads
- Large list updates in client state
- Undo and redo via patches
- Migrating codebases from Immer