R
fn

get

v0.0.15testeddemo

Shorthand accessor that unwraps a ref/getter to its value, optionally reading a single property off the resolved value. Accepts plain values, refs and getter functions (via `toValue`), so it works anywhere `unref`/`toValue` would. Purely synchronous and side-effect free, so it is fully SSR-safe.

Examples

ts
const count = ref(1);
get(count); // 1
ts
const user = ref({ name: 'Ada' });
get(user, 'name'); // 'Ada'
ts
// Works with getters and plain values too
get(() => 42); // 42
get(42); // 42

Demo

Loading demo…

Signatures

ts
export function get<T>(source: MaybeRefOrGetter<T>): T;
ts
export function get<T, K extends keyof T>(source: MaybeRefOrGetter<T>, key: K): T[K];

Type Parameters

T
Kextends keyof T

Parameters

ParameterTypeDescription
sourceMaybeRefOrGetter<T>The ref, getter or plain value to read
key?K | undefinedOptional property key to read from the resolved value

Returns

T | T[K]The unwrapped value, or `value[key]` when a key is provided