• Creates a new Computed instance. Computed is a reactive primitive that holds a value that is computed from other reactive values.

    Type Parameters

    • T

    Parameters

    • fn: (() => T)

      The function that returns the value of the Computed

        • (): T
        • Returns T

    • Optional options: {
          compareFunction: ((a, b) => boolean);
          isHardFunction: boolean;
          name: string;
      }

      Options

      • compareFunction: ((a, b) => boolean)

        A function that compares two values to determine if they are equal.

          • (a, b): boolean
          • Parameters

            Returns boolean

      • isHardFunction: boolean

        Whether the function is a hard function. If true, it prevents calling the function by comparing the string representation of the dependencies.

      • name: string

        The name of Computed.

    Returns Computed<T>

    A new Computed instance with the given function and options.

    Example

    const a = atom(0);
    const b = computed(() => a.value + 1);

    b.subscribe(() => {
    console.log(b.value);
    });

    a.value = 1;
    // b = 2