I have an object with nested objects with the below structure, how can I dynamically add new items (newData
) to the cost3
array?
I have tried that but the new data isn't being pushed, what am I doing wrong?
const [file, setFile] = useState({})
setFile(file=> ({
...file,
[cost3]: {
...file.cost3,
newData
}
}))
File
object:
{
"info": {
},
"client": {
},
"costs": {
"cost1": 1,
"cost2": 5,
"cost3": [
{
"a": "test",
"b": "test",
"c": "test",
},
{
"d": "test",
"e": "test",
"f": "test",
},
//etc..
],
"cost4": [
{
"l": "test",
"n": "test",
"m": "test",
},
//etc..
]
}
}