Distinguish drafts from plain values
A helper receives values from both reducer logic and ordinary application code.
Redux Toolkit · Function
isDraft checks whether a value is a Proxy-wrapped Immer draft state. Redux Toolkit re-exports this Immer utility for inspecting values handled during immutable update logic.
isDraft is a re-export of Immer's function. It tests whether a value is a Proxy-wrapped draft state, which is useful when code may receive either ordinary data or state currently being produced by Immer.
isDraft(value)A boolean indicating whether the supplied value is a Proxy-wrapped Immer draft.
isDraft as a re-export of the function from Immer.import { isDraft } from '@reduxjs/toolkit';
const draft = { value: 1 };
console.log(isDraft(draft)); // falseChecks whether a value is an Immer draft.
A helper receives values from both reducer logic and ordinary application code.
Reducer-related debugging needs to identify whether a value is still wrapped by Immer.
Code branches based on whether a value is managed by Immer.
isDraft determine?isDraft checks whether a value is an Immer draft represented by a Proxy wrapper. Redux Toolkit re-exports it from Immer, so it can be imported from @reduxjs/toolkit.
Follow-up: How can you inspect a draft without exposing the Proxy? Use Immer's current utility, which creates a snapshot of the current draft state.
isDraft be useful?It is useful in code that may handle both ordinary values and values currently wrapped by Immer during reducer execution. The result is a boolean indicating whether the supplied value is a draft.
Follow-up: What related utility retrieves the original value without draft updates? Immer's original utility.
isDraft related to Redux Toolkit?Redux Toolkit re-exports isDraft along with related Immer utilities. The documentation states that these exports were added to RTK as of version 1.5.1.
Follow-up: Which Redux Toolkit APIs use Immer automatically? createReducer and createSlice use Immer internally.
currentoriginalcreateReducercreateSlice