Function memo

  • Memo creates a readonly reactive value equal to the return value of the given function and makes sure that function only gets executed when its dependencies change

    const a = signal(1), b = signal(2)
    const sum = memo((prev) => a()*b() + prev, 0)
    sum()

    The memo function should not update other signals.

    Type Parameters

    • T
    • Init = T
    • K = T

    Parameters

    • fn: Fn<T>
    • Optionalvalue: Init
    • Optionaloptions: Options<T>

    Returns Getter<T>