score:3

Accepted answer

i believe that for you to take out the conditional statement, assuming that the name of the key of the order is the same as the service name from your payload, you can access and assign the key by passing the value from the payload itself. so instead of something like you have in the reducer, you will get something like this:

 const addtocart = (state, action) => {
        return {
            ...state,
            order: {
                ...state.order,
                [action.payload.service]: [...state.order[action.payload.service], action.payload.item]
            }
        }
    }


Related Query

More Query from same tag