Home > @pago/reactive > toRef
toRef() function
Extracts a single property from a tracked object into a RefObject.
Signature:
export declare function toRef<T extends object, K extends keyof T>(store: T, prop: K): RefObject<T[K]>;
Parameters
Parameter | Type | Description |
---|---|---|
store | T | A tracked object that was created through reactive(). |
prop | K | The name of the property that should be extracted into a RefObject |
Returns:
RefObject<T[K]>
Example
const state = reactive({ message: 'hello' });
const message = toRef(state, 'message');
console.log(message.current);