Immer Immutable State
immerjs.github.io
1
Leaving SiteNav
External Link Disclaimer
You are about to visit immerjs.github.io. This website is not operated by us. We are not responsible for its content or privacy practices.
About this website
Immer is a JavaScript library for working with immutable state created by Michel Weststrate, the creator of MobX, in 2017, enabling developers to write mutable code that produces immutable results through the Copy-on-Write proxy mechanism, eliminating the verbose spread operators and deep clone patterns traditionally required for immutable updates in Redux and React state management, adopted by over eight million weekly npm users and integrated into Redux Toolkit, React useState, and many state management libraries as the standard approach for immutable updates. The produce function is the core API, accepting a recipe function that receives a draft state, which is a proxied version of the original state that tracks all mutations, with the produce function returning a new immutable state containing only the changes made in the recipe while sharing all unchanged references with the original state, resulting in optimal performance through structural sharing where only modified branches of the object tree are copied. The proxy-based architecture means developers can write normal mutable JavaScript code like draft dot users dot push newUser or draft dot count plus plus inside the recipe function, with Immer automatically detecting which parts of the state tree were modified, creating copies only of those branches while preserving references to unchanged branches, producing the same result as manual immutable updates but with dramatically simpler and more readable code. The patches feature generates arrays of patches describing the changes made during produce, enabling time travel debugging, state synchronization across network, and undo and redo functionality. The current function for reading draft state. The freeze function for deep freezing objects. The TypeScript support. Designed by Michel Weststrate. Designed for React and state management.
Statistics
1
Views
0
Clicks
0
Like
0
Dislike