Can I make a Mobx observable with a custom getter?

176 views Asked by At

I have a need for a Mobx observable object which simply returns whichever property is asked of it as a string. For example, myObs.description would simply return the string "description". With a normal JS object, I would use a proxy with a custom getter, like so:

    new Proxy({}, {
      get: (obj, prop) => {
        return prop.toString();
    }})

I can't do this with Mobx as the API uses a Proxy object that I can't update. Is there a way to use Mobx to create an observable object that can have a custom computed value for any and every property passed to it?

0

There are 0 answers