Reputation: 1053
I want to ask you is that immer or not ?
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);
},
did I forgot something when to using immer ?
Upvotes: 0
Views: 175
Reputation: 44096
Should work totally fine.
The first one could also be
addProduct: (state, action: PayloadAction<Omit<IProductsListDataOnPress, 'onPress' | 'onLongPress'>>) => {
state.shopcart.push(action.payload)
},
Upvotes: 1