Search code examples
react-nativereduxredux-toolkit

is that correct with immer or is that wrong?


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 ?


Solution

  • Should work totally fine.

    The first one could also be

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