getComputedInstance

See source code

Retrieves the underlying computed instance for a given property created with the decorator.

function getComputedInstance<Obj extends object, Prop extends keyof Obj>(
  obj: Obj,
  propertyName: Prop
): Computed<Obj[Prop]>

Example

class Counter {
  max = 100
  count = atom(0)

  @computed getRemaining() {
    return this.max - this.count.get()
  }
}

const c = new Counter()
const remaining = getComputedInstance(c, 'getRemaining')
remaining.get() === 100 // true
c.count.set(13)
remaining.get() === 87 // true

Parameters

NameDescription

obj

Obj

The object

propertyName

Prop

The property name

Returns

Computed<Obj[Prop]>
Prev
computed
Next
isAtom

We use cookies on this website.
Learn more in our Cookie Policy.