Home > Enterprise >  is that correct with immer or is that wrong?
is that correct with immer or is that wrong?

Time:05-31

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 ?

CodePudding user response:

Should work totally fine.

The first one could also be

    addProduct: (state, action: PayloadAction<Omit<IProductsListDataOnPress, 'onPress' | 'onLongPress'>>) => {
      state.shopcart.push(action.payload)
    },

  • Related