Skip to content
0

katanakit-js / useCreateMemo

Function: useCreateMemo() ​

ts
function useCreateMemo<T>(computation, signals?): SignalGetter<T>;

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

Creates a memoised signal whose value is derived from a computation. The computation re-runs whenever a signal it reads changes. Explicit dependencies can also be provided for compatibility.

Type Parameters ​

Type ParameterDescription
TThe computed value type.

Parameters ​

ParameterTypeDefault valueDescription
computation() => TundefinedPure function that derives the value.
signalsSubscribable<unknown>[][]Optional explicit dependencies, in addition to tracked reads.

Returns ​

SignalGetter<T>

A read-only getter for the memoised value.

Example ​

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

Released under the MIT License.