• Creates a new computed signal.

    The compute callback will be executed (and re-executed as necessary) to provide the current value. The function body of compute is tracked automatically: any reactive values used by compute will be watched automatically; if any of them changes then the computed value will be updated as well.

    NOTE: the compute callback should not have any side effects as it may be called any number of times if its dependencies change.

    Example:

    const foo = reactive(1);
    const doubleFoo = computed(() => foo.value * 2);
    console.log(doubleFoo.value); // 2

    foo.value = 2;
    console.log(doubleFoo.value); // 4

    Type Parameters

    • T

    Parameters

    Returns ReadonlyReactive<T>