React JSX Question

problems with slice() on react-redux

I am trying to copy a state with slice(), then manipulate it and create a new state

this is my Reducer:

case types.LOAD_AMOUNT_CHECKINS_SUCCESS: {
let buildings = state.buildings.slice();

buildings['devices_error'] = action.checkins['error];
.
.
.
return Object.assign({}, state,
{buildings: buildings}
);
}


but applying slice() returns me: []

Where I have the error?

Answer

Assuming state.buildings is an object (and not an array), change the second line to this:

case types.LOAD_AMOUNT_CHECKINS_SUCCESS: {
    let buildings = Object.assign({}, state.buildings);

    buildings['devices_error'] = action.checkins['error];
    .
    .
    .
    return Object.assign({}, state,
        { buildings: buildings }
    );
}
Comments