• Creates a signal from one or more signals that are mapped using the selector function. This is slightly different from compute as all values will be recalculated even if logic in the selector only uses some.

    Type Parameters

    • const T extends FromReactiveTupleType<unknown>

      The type of the signal tuple portion of params.

    • R

      The type of the value output by the selector function

    Parameters

    Returns Signal<R>

    A readonly signal emitting the selector value

    const num1 = signal(0);
    const num2 = signal(1);
    const num3 = signal(2);
    const mapped = mapSignal(num1, num2, num3, (a, b, c) => a + b + c);
    console.log(mapped()); // 3
    num1.set(5);
    console.log(mapped()); // 8
  • Creates a signal whose input value is immediately mapped to a different value based on a selector. The selector can contain signals and will react to changes in those signals.

    Type Parameters

    • T

      The type of the initial value

    • R

      The type of the value output by the selector function

    Parameters

    • initialValue: T

      The initial value that will be run

    • selector: ((x: T) => R)

      A selector that is run after the value of the signal is changed.

        • (x): R
        • Parameters

          Returns R

    • Optionaloptions: MapSignalOptions<R>

      Can see equality function or if the selector or injector since this uses a computed function.

    Returns MapSignal<T, R>

    A writable signal whose output value is mapped with the selector.

    const addOne = mapSignal(1, x => x + 1);
    console.log(addOne()); // 2

    const addOnePlusOne = mapSignal(1, x => x + addOne());
    console.log(addOnePlusOne()); // 3