[]previous and next page

readComputation

Reads a memo node: brings it up to date if a source changed, subscribes the running computation to it, and rethrows the error its last run stored.

Reads a memo node: brings it up to date if a source changed, subscribes the running computation to it, and rethrows the error its last run stored. The accessor useMemo returns is this call.

Import#

ts
import { readComputation } from "@shadow-js/core/extend";

Signature#

ts
function readComputation<T>(node: Computation): T

Parameters#

Name Description
node A memo node from createComputation.

Returns#

The memo's current value.

Throws#

  • The error the memo's last computation threw, when no error handler took it. ShadowError CYCLE_DETECTED when the memo is read while it computes.

Examples#

ts
import { createComputation, createSignalNode, readComputation, readSignal } from "@shadow-js/core/extend";

const first = createSignalNode<string>("Ada", Object.is);
const greeting = createComputation({ kind: "memo", fn: () => `Hello, ${readSignal(first)}` });
console.log(readComputation<string>(greeting)); // "Hello, Ada"