[]previous and next page

Derived (@shadow-js/web/server)

The server twin of the client Derived: what derived returns.

The server twin of the client Derived: what derived returns. Nothing is reactive on the server, so it holds the value computed once. Read it as x.value or call it as x().

Import#

ts
import type { Derived } from "@shadow-js/web/server";

Signature#

ts
interface Derived<T> {
  /**
   * Returns the value. When the value is a function, calls it with `args` and returns its result
   * instead, so a derived function stays callable.
   */
  (...args: unknown[]): unknown;
  /** The value `compute` returned. */
  readonly value: T;
}

Members#

Name Type Description
T T
value readonly value: T The value compute returned.

Examples#

ts
import { derived } from "@shadow-js/web/server";

const total = derived(() => 20 * 3);
total.value; // 60
total(); // 60