首页 > 解决方案 > React Redux 对象数组值未在组件中更新

问题描述

我正在尝试更新对象数组项的值,但reducer 已更新而不是在组件中呈现...你能帮忙吗?

case actionTypes.UPDATE_MAGAZINE_BOOKMARK:
  const arrayObj = state.magazineListDetail;
  const updateMagazine = state.magazineListDetail.data
    .map(function(x) {
      return x.id;
    })
    .indexOf(action.magazineList);
  let newMagazineArray = [...state.magazineListDetail.data];
  newMagazineArray[updateMagazine] = {
    ...newMagazineArray[updateMagazine],
    isBookmark: !newMagazineArray[updateMagazine].isBookmark
  };
  arrayObj.data = newMagazineArray;
  return {
    ...state,
    magazineListDetail: newMagazineArray
  };

提前致谢

标签: javascriptreactjsreduxreact-redux

解决方案


推荐阅读