fn
reactivePick
v0.0.15testeddemoReactively pick a subset of keys (or keys matched by a predicate) from a reactive object. The result is a live `reactive` proxy: reads forward to the source's current value (so it tracks reassignment of nested refs) and writes pass straight back to the source. Unlike a `computed` of an object literal, no new object is allocated per recompute — the proxy is built once and lookups are resolved lazily on access.
Examples
ts
const state = reactive({ x: 1, y: 2, z: 3 });
const picked = reactivePick(state, 'x', 'y');
picked.x; // 1 — stays in sync with state.x
picked.x = 10; // writes back: state.x === 10ts
// predicate form — keep only numeric values
const filtered = reactivePick(state, (value) => typeof value === 'number');Demo
Loading demo…
Signatures
ts
export function reactivePick<T extends object, K extends keyof T>(
obj: T,
...keys: Array<K | K[]>
): ReactivePickReturn<T, K>;ts
export function reactivePick<T extends object>(
obj: T,
predicate: ReactivePickPredicate<T>,
): ReactivePickReturn<T, keyof T>;Type Parameters
Textends objectKextends keyof TParameters
| Parameter | Type | Description |
|---|---|---|
obj | T | The reactive source object (a `reactive`, `ref` value, or plain object) |
keys? | (K | K[] | ReactivePickPredicate<T>)[] | One or more keys (or arrays of keys) to pick |
Returns
ReactivePickReturn<T, K>A reactive view limited to the picked keys