P粉2450036072023-09-06 13:25:14
Since your initial state object has no defined properties, you can start with an empty initialState
object. When you have data to populate your state, you can dynamically add the [userId]
attribute to the state in the reducer. However, before doing this, you must first initialize the property with an empty object and then assign it { cart:[] }
. See the Example in the documentation, where there is a paragraph that says: Immer does not automatically create nested objects or arrays for you - you must create them yourself.