I am trying to change the state of my app without overriding the values that haven't changed. I am doing so using the spread operator, but something is going wrong.
Here is my base state : useState({data : [{name : undefined , project : []}] });
With setState
i want to just add names but keep the project array empty since it didn't change.
setManager(prevState => ({...prevState , data : res.data}))
After performing setState the new state looks like this :
[
{name: "John doe"},
{name: "Jane Doe"}
]
as you can see the default state is completely overridden.
res.data looks like this by the way :
[
{name: "john doe"},
{name: "jane doe"}
]