Skip to content

@jsvision/ui / computed

Function: computed() ​

computed<T>(fn, options?): Computed<T>

Defined in: ui/src/reactive/computed.ts:47

Create a lazy, memoized derived value.

Type Parameters ​

T ​

T

Parameters ​

fn ​

() => T

The derivation; the signals/computeds it reads become its dependencies (re-collected on each recompute). Must be pure — no signal writes.

options? ​

ComputedOptions<T>

Optional equality policy for the derived value — see ComputedOptions.

Returns ​

Computed<T>

A read-only callable accessor: call it to read (and, inside a tracked computation, subscribe); .peek() reads the current value without subscribing.

Example ​

ts
import { signal, computed, effect } from '@jsvision/ui';

const price = signal(10);
const qty = signal(2);
const total = computed(() => price() * qty());

effect(() => console.log('total:', total())); // "total: 20"
qty.set(3);                                    // "total: 30"
total();                                       // 30, returned from cache (not recomputed)