[{
accountNumber: "1111111",
id: 1,
timeRecords: [{
id: 0,
hours: '1'
}, {
id: 1,
hours: '2'
}, {
id: 2,
hours: '3'
}]
}]
решение может выглядеть чрезмерно сложным, но это правильный способ мутировать
deleteRecord = (recordID, userID) => {
const list = this.state.employeesList;
const index = list(v => v.id === userID)
const nestedList = list[index].timeRecords
const nestedIndex = nestedList.findIndex(v => v.id === recordID)
return [
...list.slice(0, index), // get items before the userID
{
...list[index], // fill other pros of userID
timeRecords: [ // remove item by recordID
...nestedList.slice(0, nestedIndex),
...nestedList.slice(nestedIndex + 1)
]
},
...list.slice(index + 1) // get items after the userID
]
}