• Creates a new Atom instance. An Atom is a reactive primitive that holds a value. Same as atom but returns a new Atom instance.

    Type Parameters

    • T

    Parameters

    • value: T

      The initial value of the Atom.

    • Optional options: {
          compareFunction: ((a, b) => 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

      • name: string

        The name of Atom.

    Returns Atom<T>

    A new Atom instance with the given value and options.

    Example

    const count = atom(0);

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

    count.value = 1;