score:9

Accepted answer

You're spreading an object inside an array, to fix that you should spread the items property inside an array:

function manageList(state = { items: [] }, action) {
  switch (action.type) {
    case ADD_ITEM:
      return { list: [...state.items, action.payload] };
    case RESET_LIST:
      return {
        items: [...state.items, []],
      };
    default:
      return state;
  }
}

I think also that you should replace list and item by items :

function manageList(state = { items: [] }, action) {
  switch (action.type) {
    case ADD_ITEM:
      return { items: [...state.items, action.payload] };
    case RESET_LIST:
      return {
        items: [...state.items, []],
      };
    default:
      return state;
  }
}

score:1

export const commentReducer = (state = initialState, action) => {
  switch (action.type) {
    case COMMENT_REQUEST:
      return {
        ...state,
        loading: true,
      };
    case COMMENT_SUCCESS:
      return {
        ...state,
        comment: [...state.comment, action.payload],
      };
    case COMMENT_FAIL:
      return { loading: false, error: action.payload };
    default:
      return state;
  }
};

It works for me

score:2

I think you should spread them as "state.items" not as just "state".

Like this:

item: [...state.items,[]] 

Not like this:

item: [...state,[]]

Related Query

More Query from same tag