immer 是正确的还是错误的?
is that correct with immer or is that wrong?
我想问你是不是沉浸在里面?
addProduct: (state, action: PayloadAction<Omit<IProductsListDataOnPress, 'onPress' | 'onLongPress'>>) => {
state.shopcart = [...state.shopcart, action.payload]
},
removeProduct: (state, action: PayloadAction<{ id: string; }>) => {
state.shopcart = state.shopcart.filter(el => el.id !== action.payload.id);
},
我在使用 immer 时是不是忘记了什么?
应该可以正常工作。
第一个也可以
addProduct: (state, action: PayloadAction<Omit<IProductsListDataOnPress, 'onPress' | 'onLongPress'>>) => {
state.shopcart.push(action.payload)
},
我想问你是不是沉浸在里面?
addProduct: (state, action: PayloadAction<Omit<IProductsListDataOnPress, 'onPress' | 'onLongPress'>>) => {
state.shopcart = [...state.shopcart, action.payload]
},
removeProduct: (state, action: PayloadAction<{ id: string; }>) => {
state.shopcart = state.shopcart.filter(el => el.id !== action.payload.id);
},
我在使用 immer 时是不是忘记了什么?
应该可以正常工作。
第一个也可以
addProduct: (state, action: PayloadAction<Omit<IProductsListDataOnPress, 'onPress' | 'onLongPress'>>) => {
state.shopcart.push(action.payload)
},