我真的很纠结于此,我想在我的"binnacleNotesReducer“中的"binnacleNotes”属性中添加一个新的项目,我已经尝试了几种方法,我在互联网上找到了不好的结果。
新注释要么被添加到主属性"binnaceNotesReducer“中,要么不被添加。
我有以下redux结构:

请参考我在以下代码中的几次尝试:
case ADD_NEW_NOTE:
const { id, date, binnacle_note, responsibleState, attachments, constructor_review, super_review, dro_review, timestamp } = payload;
const newNote = {
binnacleNotes: {
id,
date,
binnacle_note,
responsibleState,
attachments,
constructor_review,
super_review,
dro_review,
timestamp,
},
};
//return state.binnacleNotes.concat(newNote);
return {
...state.binnacleNotes,
binnacleNotes: {
...state.binnacleNotes,
id,
date,
binnacle_note,
responsibleState,
attachments,
constructor_review,
super_review,
dro_review,
timestamp,
},
};不同的方法:
case ADD_NEW_NOTE:
const { id, date, binnacle_note, responsibleState, attachments, constructor_review, super_review, dro_review, timestamp } = payload;
const newNote = {
binnacleNotes: {
id,
date,
binnacle_note,
responsibleState,
attachments,
constructor_review,
super_review,
dro_review,
timestamp,
}
}
return state.binnacleNotes.concat(newNote);发布于 2021-04-13 00:21:14
在阅读了更多的文档后,我找到了解决方案,希望这对任何人都有帮助:
case ADD_NEW_NOTE:
const { id, date, binnacle_note, responsible, attachments, constructor_review, super_review, dro_review, timestamp } = payload;
return {
binnacleNotes: [
...state.binnacleNotes,
{ id, date, binnacle_note, responsible, attachments, constructor_review, super_review, dro_review, timestamp },
],
};https://stackoverflow.com/questions/67060252
复制相似问题