Skip to content

ComputedFunction type

Home > @rimitive/signals > ComputedFunction

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;
};
const count = signal(5);
const doubled: ComputedFunction<number> = computed(() => count() * 2);
doubled(); // computes: 10
doubled(); // cached: 10
count(10); // marks doubled as stale
doubled(); // recomputes: 20
doubled.peek(); // read without tracking: 20