Skip to content
Myr

[docs] Documented setUseStrictIteration

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Michel Weststrate · committed by Michel Weststrate · parent d38a9d0 · Browse files · 2 files+16 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+16 added−4 removed

  • other:+16 added−4 removed

2 files+16 added−4 removed

modified:website/docs/api.md+1 added
modified:website/docs/performance.mdx+15 added-4 removed
7 unmodified lines
8 data-ea-publisher="immerjs"9 data-ea-type="image"10 className="horizontal bordered"11 ></div>12</center>13<details>12</center> <details>13 <summary className="egghead-summary">14 egghead.io lesson 5: Leveraging Immer's structural sharing in React15 </summary>16 <br />
10 unmodified lines
27 href="https://egghead.io/lessons/react-profile-react-rendering-and-optimize-with-memo-to-leverage-structural-sharing"28 >29 Hosted on egghead.io30 </a>32</details>33<details>31</details> <details>32 <summary className="egghead-summary">33 egghead.io lesson 7: Immer will try to re-cycle data if there was no34 semantic change35 </summary>
41 unmodified lines
77```7879This plugin optimizes array operations like `filter`, `find`, `some`, `every`, and `slice` by avoiding proxy creation for every element during iteration. Without the plugin, iterating a 1000-element array creates 1000+ proxies. With the plugin, callbacks receive base values, and proxies are only created for elements you actually mutate.8081### Use loose iteration for better performance8283By default, Immer uses loose iteration which only processes enumerable string properties. This is faster than strict iteration which includes symbols and non-enumerable properties. For most use cases, the default is optimal:8485```javascript86import {setUseStrictIteration} from "immer"8788// Default: false (loose iteration for better performance)89setUseStrictIteration(false)90```9192Only enable strict iteration if you specifically need to track symbol or non-enumerable properties.9394### Pre-freeze data9596When adding a large data set to the state tree in an Immer producer (for example data received from a JSON endpoint), it is worth to call `freeze(json)` on the root of the data that is being added first. To _shallowly_ freeze it. This will allow Immer to add the new data to the tree faster, as it will avoid the need to _recursively_ scan and freeze the new data.97
11 unmodified lines