破坏覆盖现有价值

轰炸机

我试图在下面的减速器中更新状态。

结果对象具有两个数组:

results: {
    correctAnswers: [7]
    incorrectAnswers: (9) [0, 1, 2, 3, 4, 5, 6, 8, 9]
}

如何添加totalScore到结果对象?下面的代码添加totalScore,但删除correctAnswersincorrectAnswers

case "COMPLETE_QUIZ": {
  const { totalScore, id } = action.data;
  console.log(action.data, state);
  return {
    videos: state.videos.map(video =>
      video.id === id
        ? {
            ...video,
            results: {
              totalScore \\ add here
            },
            completed: true
          }
        : video
    ),
    search: { term: "", videos: [] }
  };
}
杜波卡斯

spread 原始对象并添加新属性

results: {
    ...state.results,
    totalScore
},

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章