Skip to content
Myr

freezing.mdx

This file

Path

website/docs/freezing.mdx

39 lines · 1.6 KiB

Last changed by

docs: Update to docusaurus 2Michel Weststratebefore adoption42aac95

History of this file

Take it

docs: Update to docusaurus 2Michel Weststratebefore adoption42aac95

lines 1–39why, one step back
1---
2id: freezing3title: Auto freezing4---56<center>7 <div8 data-ea-publisher="immerjs"9 data-ea-type="image"10 className="horizontal bordered"11 ></div>12</center> <details>13 <summary className="egghead-summary">14 egghead.io lesson 7: Immer automatically freezes data15 </summary>16 <br />17 <div>18 <iframe19 width="760"20 height="427"21 scrolling="no"22 src="https://egghead.io/lessons/javascript-produces-immutable-data-and-avoid-unnecessary-creation-of-new-data-trees-with-immer/embed"23 ></iframe>24 </div>25 <a26 className="egghead-link"27 href="https://egghead.io/lessons/javascript-produces-immutable-data-and-avoid-unnecessary-creation-of-new-data-trees-with-immer"28 >29 Hosted on egghead.io30 </a>31</details>3233Immer automatically freezes any state trees that are modified using `produce`. This protects against accidental modifications of the state tree outside of a producer. In most cases this provides the most optimal behavior, but `setAutoFreeze(true / false)` can be used to explicitly turn this feature on or off.3435Immer will never freeze (the contents of) non-enumerable, non-own or symbolic properties, unless their content was drafted.3637_⚠️ Immer freezes everything recursively, for large data objects that won't be changed in the future this might be over-kill, in that case it can be more efficient to shallowly pre-freeze data using the `freeze` utility.⚠️_3839_⚠️ If auto freezing is enabled, recipes are not entirely side-effect free: Any plain object or array that ends up in the produced result, will be frozen, even when these objects were not frozen before the start of the producer! ⚠️_