I have an issue with updating deep nested array. Here’s an example of my data structure and what I want to change. If anyone could show me the pattern of accessing this update (title) using spread operator
currentPage:{
id:'484512',
page:{
content:[
{comp:1,
grids:[
{id:1,
title: 'some data1', //how can I update title with spread operator?
description: 'some data'},
{id:2,
title: 'some data2',
description: 'some data'}
]
},
{comp:2},
{comp:3}]
}
}
var compIndex = this.state.currentPage.page.content.findIndex(obj => obj.id === compId
);
var cardIndex = this.state.currentPage.page.content[compIndex].grids.findIndex(obj => obj.id === cardId);
this.setState(prevState => ({
currentPage: {
...prevState.currentPage,
page: {
...prevState.currentPage.page,
content: [
...prevState.currentPage.page.content[compIndex],
grids: {
...prevState.currentPage.page.content[compIndex].grids[cardIndex],
[sec]: value
}
]
}
}
}));