Okay, I have a useState object in react that I’m trying to update and it only works as detaild below. There’s the initial object and I have an object from the server that has null and non-null fields. I want to update only the non-null fields on the initial object. The view doesn’t re-render when trying to update the initial object. The following works, but I can’t leave out the null fields:
[test, setTest] = useState();
let data = client.update();
setTest(test => {
return {...test, area: data.area};
});
This doesn’t work:
setTest(test => {
let update = test;
if(data.area !== null){
update.area = data.area;
}
/// doesn't work
return update;
})
This doesn’t work either:
setTest(test => {
let update = test;
if(data.area !== null){
update.area = data.area;
}
// doesn't work
return Object.assign(test, update);
});