Javascript 当我试图基于另一个对象数组修改一个对象数组中的属性时,会引发状态突变错误

Javascript 当我试图基于另一个对象数组修改一个对象数组中的属性时,会引发状态突变错误,javascript,reactjs,ecmascript-6,Javascript,Reactjs,Ecmascript 6,我有两个对象数组,一个默认值,另一个保存在本地状态 Array 1 DefaultArray = [{type: typeA, isImportant: true, Content: ContentDefaultforA}, {type: typeB, isImportant: true, Content1: ContentDefaultforB1, Content2: ContentDefaultforB2}, {type: typeC, isImportant: false, Conte

我有两个对象数组,一个默认值,另一个保存在本地状态

Array 1
DefaultArray =  
[{type: typeA, isImportant: true, Content: ContentDefaultforA}, {type: typeB, isImportant: true, Content1: ContentDefaultforB1, Content2: ContentDefaultforB2}, {type: typeC, isImportant: false, Content: ContentDefaultforC}, {type: typeD, isImportant: false, Content: ContentDefaultforD}]
价值

this.state.newArray = 
[{type: typeB, isImportant: true, Content1: ContentDefaultforB1, Content2: ContentDefaultforB2}, {type: typeA, isImportant: true, Content: ModifiedContentForA}, {type: typeD, Content: ModifiedCOntentForD, isImportant: true}, {type: typeC, isImportant: true, Content: ModifiedCOntentForC}]
我想比较2个数组,并将this.state.newArray中的isImportant属性更改为默认数组中的whats 所以我想要的结果是

this.state.newArray = 
[{type: typeB, isImportant: true,, Content1: ContentDefaultforB1, isImportant: true, Content2: ContentDefaultforB2}, {type: typeA, isImportant: true, Content: ModifiedContentForA}, {type: typeD, Content: ModifiedCOntentForD, isImportant: false}, {type: typeC, isImportant: false, Content: ModifiedCOntentForC}]
我正在这样做

let arrayCopy = [...this.state.newArray]
arrayCopy.forEach(item=>{
            let isImportant = defaultArray.filter(defaultItem=>defaultItem.type===item.type)[0].isImportant
            item.isImportant = isImportant
        })
这引发了一个状态突变


这怎么能解决呢?另外,是否有更简单的方法使用lodash执行此操作?您正在(浅)复制数组,但没有复制其
.isImportant
属性发生变化的对象。请使用codesandbox制作片段