JSFiddle - React, Tailwind, and code Playground

by Scott Kaye

Babel + JSX

function reducer(state, action) {
    return {
        ...state,
        selectedStorage: state.selectedStorage.storageItems.map(i => {
            if (i.id != action.payload) return i;
            return {
                ...i,
                qty: i.qty - 1
            }
        })
    }
}

let newState = reducer({
    selectedStorage: {
        storageItems: [{
            id: "one",
            qty: 6
        }, {
            id: "two",
            qty: 4
        }]
    }
}, {
    payload: "one"
});

console.log(newState);