import { useRef } from "react";
import { computed, IComputedValueOptions, IComputedValue } from "mobx";

export function useComputed<T>(expr: () => T, options?: IComputedValueOptions<T>): T {
    const ref = useRef<IComputedValue<T>>();
    if (ref.current == null) {
        ref.current = computed(expr, options)
    }
    return ref.current.get();
}
