[]previous and next page

derived (@shadow-js/web/server)

The server twin of the client derived, which the compiler emits for const x = <expression reading signals> inside a component.

The server twin of the client derived, which the compiler emits for const x = <expression reading signals> inside a component. On the server it calls compute once, immediately, and returns a constant Derived.

Import#

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

Signature#

ts
function derived<T>(compute: () => T): Derived<T>

Parameters#

Name Description
compute The computation. Runs once, when derived is called; an error it throws propagates.

Returns#

A Derived holding the result.

Examples#

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

const greeting = derived(() => (name: string) => `Hello, ${name}`);
greeting("Ada"); // "Hello, Ada": a derived function stays callable