ComputedFunction type
Home > @rimitive/signals > ComputedFunction
ComputedFunction type
Section titled “ComputedFunction type”Computed function type - a callable that derives values from other reactives.
Computeds are lazy: they only recompute when read and their dependencies have changed. Use .peek() to read without tracking dependencies.
Signature:
export type ComputedFunction<T = unknown> = { (): T; peek(): T;};Example
Section titled “Example”const count = signal(5);const doubled: ComputedFunction<number> = computed(() => count() * 2);
doubled(); // computes: 10doubled(); // cached: 10count(10); // marks doubled as staledoubled(); // recomputes: 20doubled.peek(); // read without tracking: 20