Bom*_*ber 1 javascript reactjs redux
我试图在下面的减速器中更新状态。
结果对象具有两个数组:
results: {
correctAnswers: [7]
incorrectAnswers: (9) [0, 1, 2, 3, 4, 5, 6, 8, 9]
}
Run Code Online (Sandbox Code Playgroud)
如何添加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: [] }
};
}
Run Code Online (Sandbox Code Playgroud)
spread 原始对象并添加新属性
results: {
...state.results,
totalScore
},
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
57 次 |
| 最近记录: |