Skip to content
Myr

docs: Readme fixes

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

authored by Michel Weststrate · committed by Alec Larson · parent 7820eee · Browse files · 1 file+2 added−21 removed
This commit

State

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

Diff stats

1 file+2 added−21 removed

  • other:+2 added−21 removed

1 file+2 added−21 removed

modified:readme.md+2 added-21 removed
633 unmodified lines
634const newState = increment(state, 2)635// `newState.x` cannot be modified here636```637638**Note:** Immer v1.9+ supports Typescript v3.1+ only. **Note:** Immer v2.2+ supports Typescript v3.4+ only.638**Note:** Immer v1.9+ supports TypeScript v3.1+ only.639640## Using `this`640**Note:** Immer v3.0+ supports TypeScript v3.4+ only.641642The recipe will be always invoked with the `draft` as `this` context.643644This means that the following constructions are also valid:645646```javascript647const base = {counter: 0}648649const next = produce(base, function() {650 this.counter++651})652console.log(next.counter) // 1653654// OR655const increment = produce(function() {656 this.counter++657})658console.log(increment(base).counter) // 1659```660642# Pitfalls6436441. Don't redefine draft like, `draft = myCoolNewState`. Instead, either modify the `draft` or return a new state. See [Returning data from producers](#returning-data-from-producers).6451. Immer assumes your state to be a unidirectional tree. That is, no object should appear twice in the tree, and there should be no circular references.
143 unmodified lines