Skip to content
module@warp-drive/alien-signals/primitives

Function readMemo() sincev5.10.0 ​

ts
function readMemo<T>(memo: MemoNode<T>): T;

Defined in: primitives.ts:307

Returns the latest result of memo, running its function only if something it read changed since the last run. Inside another memo, that memo now depends on memo.

Throws the cached error if the function threw, and throws if memo reads itself, directly or through other memos.

Type Parameters ​

T ​

T

Parameters ​

memo ​

MemoNode<T>

the memo to read

Returns ​

T

the memo's current result

Example ​

ts
import { createMemo, readMemo } from '@warp-drive/alien-signals/primitives';

const total = createMemo(cart, 'total', () => cart.items.reduce((sum, item) => sum + item.price, 0));
readMemo(total);

Released under the MIT License.