79553824

Date: 2025-04-03 19:33:28
Score: 1
Natty:
Report link

When you use Redux Toolkit (createSlice), Immer automatically creates a draft copy of the state so that you can "mutate" it directly. However:

If state is a primitive (number, string, boolean) → Immer cannot create a draft because drafts only work on reference types (objects/arrays).

When state is an array or object → Immer tracks changes and applies them correctly.

let loggerSlice = createSlice({
    name:"logger",
    initialState:"",   //will not work instead use { msg :""}
  })
Reasons:
  • Has code block (-0.5):
  • Starts with a question (0.5): When you use
  • Low reputation (1):
Posted by: Shubham More