One of the elements in state is happened to be nested array containing objects like below:
this.state = {
department: [
[
{
"name": {
"firstName": "John",
"lastName": "Joestar"
},
"age": 29
},
{
"name": {
"firstName": "George",
"lastName": "Thomas"
},
"age": 24
}
],
[
{
"name": {
"firstName": "Mary",
"lastName": "Jane"
},
"age": 40
}
]
]
}
Now suppose I need to update the firstName
at department[0][0].name.firstName
to Joseph. What is the correct way to update firstName
using setState
w/o compromising efficiency?