R
fn

computedEager

v0.0.15testeddemo

Eager (non-lazy) computed value backed by a `watchEffect`-driven `shallowRef`. Unlike `computed`, the getter runs immediately and on every dependency change rather than lazily on read, so the cached value is always up to date. Best for cheap derived values that are read in many places.

Examples

ts
const count = ref(0);
const isEven = computedEager(() => count.value % 2 === 0);
isEven.value; // true
ts
// Defer recomputation until after the component update flush
const total = computedEager(() => a.value + b.value, { flush: 'post' });

Demo

Loading demo…

Signature

ts
export function computedEager<T>(getter: () => T, options: ComputedEagerOptions ={ ... }

Type Parameters

T

Parameters

ParameterTypeDescription
getter() => TThe effect function deriving the value
options?ComputedEagerOptionsWatch options (`flush` defaults to `'sync'`)

Returns

Readonly<ShallowRef<T>>A readonly shallow ref holding the derived value