original.md
This file
Path
docs/original.md
32 lines · 1000 bytes · Markdown
Last changed by
Merge pull request #493 from scilganon/patch-1Michel Weststratebefore adoption98794b8
History of this fileTake it
Merge pull request #421 from immerjs/docsMichel Weststratebefore adoption9be6e46
lines 1–11why, one step back1---2id: original3title: Extracting the original object from a proxied instance4sidebar_label: Original5---67<div id="codefund"><!-- fallback content --></div>89Immer exposes a named export `original` that will get the original object from the proxied instance inside `produce` (or return `undefined` for unproxied values). A good example of when this can be useful is when searching for nodes in a tree-like state using strict equality.1011```jsMerge pull request #493 from scilganon/patch-1Michel Weststratebefore adoption98794b8
line 12why, one step back12import {original, produce} from "immer"Merge pull request #421 from immerjs/docsMichel Weststratebefore adoption9be6e46
lines 13–22why, one step back1314const baseState = {users: [{name: "Richie"}]}15const nextState = produce(baseState, draftState => {16 original(draftState.users) // is === baseState.users17})18```1920Just want to know if a value is a proxied instance? Use the `isDraft` function!2122```jsMerge pull request #493 from scilganon/patch-1Michel Weststratebefore adoption98794b8
line 23why, one step back23import {isDraft, produce} from "immer"Merge pull request #421 from immerjs/docsMichel Weststratebefore adoption9be6e46
lines 24–32why, one step back2425const baseState = {users: [{name: "Bobby"}]}26const nextState = produce(baseState, draft => {27 isDraft(draft) // => true28 isDraft(draft.users) // => true29 isDraft(draft.users[0]) // => true30})31isDraft(nextState) // => false32```