I am trying to set my Context API object as below in one of functional components as below;
I set it 3 times in the same component as below;
let tmpObj = {
user1: props.user1,
user2: props.user2
}
// Below is NOT retained
setMyContextApiObj({
...myContextApiObj,
tmpObj
});
//This one is retained
setMyContextApiObj({
...myContextApiObj,
myValFromStorage: myValFromStorage
});
//This one is retained
setMyContextApiObj({
...myContextApiObj,
myPref: myPref
});
However, for some reason, I only get the myValFromStorage and myPref values once I am out of this component and not the tmpObj one.
Not sure why that value is not getting retained in the Context API