Function computedProp

  • Create a computed property on an object that is used as a function that takes the object as an argument and returns the computed value.

    If the passed object is not an observable it will return the value without ever caching it.

    Example:

    const getPointDistance = computedProp<Point>(
    ({ x, y }) => Math.sqrt(x ** 2 + y ** 2)
    )

    // this will be a computed value
    getPointDistance(somePoint)

    You can pass as optional second argument the options for the computed value, the same that MobX takes for its computed function.

    If you ever need to get the actual computed used for the computed property you can access it through the getComputedFor property of the returned function.

    Type Parameters

    • T extends object
    • R

    Parameters

    • fn: (obj: T) => R
    • Optionaloptions: IComputedValueOptions<R>

    Returns ComputedPropFn<T, R>