Skip to content
Myr

Merge pull request #183 from drcmda/patch-1

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

Add small section explaining how to use "void" for inline mutations

authored by Michel Weststrate · committed by GitHub · parents f8479c2, 67d7ba9 · Browse files · 1 file+14 added−0 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+14 added−0 removed

  • other:+14 added−0 removed

1 file+14 added−0 removed

modified:readme.md+14 added
381 unmodified lines
382})383console.log(increment(base).counter) // 1384```385386## Inline shortcuts using `void`387388Draft mutations in Immer usually warrant a code block, since a return denotes an overwrite. Sometimes that can stretch code a little more than you might be comfortable with. 389390In such cases you can use javascripts [`void`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/void) operator, which evaluates expressions and returns `undefined`.391392```javascript393// Single mutation394produce(draft => void (draft.user.age += 1))395396// Multiple mutations397produce(draft => void (draft.user.age += 1, draft.user.height = 186))398```399400## TypeScript or Flow401402The 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.403
218 unmodified lines