Javascript splice working wrong with redux

  javascript, reactjs, redux

My splice is deleting everything but item clicked.
I have studied a popular post here about that, but it didn’t worked for me, same for that one about redux and modifying a state.
I have a redux function which is meant to delete an item – action.item contains an unique index of an item that I want to be deleted:

const deleteItem = (state, action) => {
    return updateObject(state, {
        orderedItems: state.orderedItems.splice(action.item, 1)
    });
};

updateObject looks like that:

export const updateObject = (oldObject, updatedProperties) => {
    return {
        ...oldObject,
        ...updatedProperties
    };
};

Different solutions as f.e:

const deleteItem = (state, action) => {
    return state.orderedItems.filter(element => element !== action.item);
};

Not only don’t work, but also gives me TypeError: Cannot read property ‘map’ of undefined because im using mapping to show every item

let basket = (
            <aside>
                {this.props.orderedItems.map((orderItem, i) => (
                    <OrderElement key={i} id={i} title={orderItem.item} />
                ))}
            </aside>
        );

Thats an initial state of the store:

const initialState = {
    loading: false,
    numberOfReservations: "",
    orderedItems: [],
};

Before clicking Reco3:
Page before clicking an item to delete
And after clicking:
Page after clicking and Reco3 item
Im completly clueless, thanks in advance for help.

Source: Ask Javascript Questions

LEAVE A COMMENT