I am getting an empty object when I do toJS() on an observable object. I am assigning the values to the observableObject
after an API call using Object.assign(). Now I am using this observableObject
in a computed method of different store as shown in the code below.
class Store {
@observable observableObject = {};
Fetch(){
.....
APIcall()
.then((response) => {
Object.assign(this.observableObject, response.data);
}).catch(...)
}
.....
}
class Store2 {
@computed get computedValue(){
// return an non empty {Symbol(mobx administration): ObservableObjectAdministration$$1} object
console.log(this.rootStore.store1.observableObject);
// returns True
console.log(isObservable(this.rootStore.store1.observableObject));
// return an empty object
console.log(toJS(this.rootStore.store1.observableObject));
}
}
I have referred to this issue but couldn't find any help. Find the log of the observableObject
below. Can anyone explain the unexpected bheviour of toJS()
in mobx.
EDIT: The target field in the log of proxy mobx observable contains all fields but toJS() conversion yields empty object. Here is the sandbox demo