DEV Community

Discussion on: React, TypeScript & Mobx

Collapse
 
theonlybeardedbeast profile image
TheOnlyBeardedBeast

I like to use getters and setter so I can set store values directly inside the module, a setter automatically becomes an action, no need to decorate it.

  @observable protected _accessToken: Maybe<string> = null;
  @computed public get accessToken(): Maybe<string> {
    return this._accessToken;
  }
  public set accessToken(v: Maybe<string>) {
    this._accessToken = v;
  }
Collapse
 
shevchenkonik profile image
Nik Shevchenko • Edited

Thanks for your feedback!

I know this way, but I don't really understand its advantages over actions.

What is the advantage of that?

Collapse
 
theonlybeardedbeast profile image
TheOnlyBeardedBeast

Shifting action logic into your components/modules. A lot of times it can be handy, but yeah I do too prefer the way you described mobx usage, but I always crete getters and setters.