Saltar al contenido principal

Function: useCreateMemo()

useCreateMemo<T>(computation, signals): SignalGetter<T>

Defined in: src/core/services/reactive.service.ts:179

Creates a memoised signal whose value is derived from a computation. The computation re-runs whenever any of the provided signals change.

Type Parameters

T

T

The computed value type.

Parameters

computation

() => T

Pure function that derives the value.

signals

Subscribable<unknown>[]

Signals the computation depends on.

Returns

SignalGetter<T>

A read-only getter for the memoised value.

Example

const [a, setA] = useCreateSignal(2);
const [b, setB] = useCreateSignal(3);
const sum = useCreateMemo(() => a() + b(), [a, b]);
sum(); // 5
setA(10);
sum(); // 13