我试图在下面的减速器中更新状态。
结果对象具有两个数组:
results: {
correctAnswers: [7]
incorrectAnswers: (9) [0, 1, 2, 3, 4, 5, 6, 8, 9]
}
如何添加totalScore
到结果对象?下面的代码添加totalScore
,但删除correctAnswers
和incorrectAnswers
。
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] 删除。
我来说两句