I have an api to return the result which is the nested object. And initially state is as shown below:
const [obj, setObj] = useState({
name: null,
age: null,
address: {
city: null,
zipCode: null
}
})
Once the api gets called and return the result which contains all the properties, we will call setObj. Do we need to call like setObj({...obj, results})
or we can call setObj(results)
directly?
Per my unerstanding, state is immutable in react and we cannot modify it directly. Please correct me if I am wrong. a smiliar quesiton I found is Why can't I directly modify a component's state, really?
thanks in advance.