Skip to content
Myr

original.md

This file

Path

docs/original.md

32 lines · 982 bytes · Markdown

Last changed by

Merge pull request #421 from immerjs/docsMichel Weststratebefore adoption9be6e46

History of this file

Take it

Merge pull request #421 from immerjs/docsMichel Weststratebefore adoption9be6e46

lines 1–32why, one step back
1---
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```js12import {original} from "immer"1314const 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```js23import {isDraft} from "immer"2425const 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```