object is not being picked up as observable

18 Views Asked by At

I'm using mobx to set an object which is a member of a class. But when the object (that is an observable for the class) changes, the view is not picking up that change. Can someone please help? Here's my code

export class Test {

   @observable
   private _person? : Person;

   constructor() {
       makeObservable(this);
   }

   @action 
   public setCurrentPerson(person?: Person) {
      this._currentPerson = person;
   }

   @computed
   public get currentPerson() {
       return this._currentPerson;
   }

When I call the function setCurrentPerson, the view that relies on the value for _currentPerson does not get updated. But when I change string variables of the class, it does. Can someone please help? I'm using mobx, typescript and web components.

0

There are 0 best solutions below