
Introduction to Immer - GitHub Pages
Immer (German for: always) is a tiny package that allows you to work with immutable state in a more convenient way.
Immer 入门 - GitHub Pages
Immer(德语为:always)是一个小型包,可让您以更方便的方式使用不可变状态。 Immer 简化了不可变数据结构的处理 Immer 可以在需要使用不可变数据结构的任何上下文中使用。 例如与 React state、React 或 Redux reducers 或者 configuration management 结合使用。
Using produce | Immer - GitHub Pages
The Immer package exposes a produce function that does all the work. produce(baseState, recipe: (draftState) => void): nextState produce takes a base state, and a recipe that can be used to perform all the desired mutations on the draft that is passed in.
Installation | Immer - GitHub Pages
To make sure Immer is as small as possible, features that are not required by every project has been made opt-in, and have to be enabled explicitly. This ensures that when bundling your application for production, unused features don't take any space.
Using TypeScript or Flow | Immer - GitHub Pages
The Immer package ships with type definitions inside the package, which should be picked up by TypeScript and Flow out of the box and without further configuration. The TypeScript typings automatically remove readonly modifiers from your draft types and return a value that matches your original type. See this practical example:
React & Immer | Immer - GitHub Pages
Deep updates in the state of React components can be greatly simplified as by using Immer. The following example shows how to use produce in combination with useState, and can be tried on CodeSandbox.
API overview | Immer - GitHub Pages
Importing immer In most cases, the only thing you need to import from Immer is produce:
使用 produce | Immer - GitHub Pages
produce(currentState, recipe: (draftState) => void): nextState produce 需要一个 baseState,以及一个可用于对传入的 draft 进行所有所需更改的 recipe。 关于 Immer 的有趣之处在于 baseState 将保持不变,但 nextState 将反映对 DraftState 所做的所有更改.
Immer performance - GitHub Pages
Immer will convert anything you read in a draft recursively into a draft as well. If you have expensive side effect free operations on a draft that involves a lot of reading, for example finding an index using find(Index) in a very large array, you can speed this up by first doing the search, and only call the produce function once you know the ...
Frequently Asked Questions | Immer - GitHub Pages
Q: How does Immer work? Read the (second part of the) introduction blog. Q: Does Immer use structural sharing? So that my selectors can be memoized and such? A: Yes Q: Does Immer support deep updates? A: Yes Q: I can't rely on Proxies being present on my target environments. Can I use Immer? A: Yes - view details