Search
Loading...
Skip to content

Function: _createDerivedProperty

function _createDerivedProperty<T, S>(
sources,
derive,
options?): _ReadonlyReactiveProperty<T>;

Creates a derived reactive property from one or more sources.

The value is computed from source values using a derivation function. Updates are memoized (only emit when derived value changes).

Type Parameters#

Type Parameter
T
S extends any[]

Parameters#

ParameterTypeDescription
sources{ [K in stringnumber
derive(…values) => TFunction that computes the derived value from source values
options?Pick<_ReactivePropertyOptions<T>, "equals">Configuration options

Returns#

_ReadonlyReactiveProperty<T>

A read-only reactive property

Example#

const width = createReactiveProperty(800);
const height = createReactiveProperty(600);
const area = createDerivedProperty(
[width, height],
(w, h) => w * h
);
area.subscribe((value) => console.log('Area:', value));
width.update(1000); // Logs: "Area: 600000"