fn
set
v0.0.15testeddemoShorthand setter that mirrors {@link get}. Either assigns `value` to a ref (`ref.value = value`) or assigns `value` to a single property of an object (`target[key] = value`). The arity is resolved at the type level via overloads, so both forms stay fully type-safe. Purely synchronous and side-effect free, so it is fully SSR-safe.
Examples
ts
const count = ref(0);
set(count, 5); // count.value === 5ts
const user = reactive({ name: 'Ada' });
set(user, 'name', 'Grace'); // user.name === 'Grace'Demo
Loading demo…
Signatures
ts
export function set<T>(ref: Ref<T>, value: T): void;ts
export function set<O extends object, K extends keyof O>(target: O, key: K, value: O[K]): void;Type Parameters
Oextends objectKextends keyof OParameters
| Parameter | Type | Description |
|---|---|---|
target | Ref<unknown, unknown> | O | The ref to write to, or the object to mutate |
valueOrKey | unknown | The value to assign to the ref, or the key to mutate |
value? | O[K] | undefined | The value to assign to the ref, or the key to mutate |