Home > @pago/reactive > reactive
reactive() function
Transforms an object into a tracked version. Changing the object returned from reactive
will also change the original. All watchers and derived values will update. Access to Object.keys
as well as checking for the existance of a key through the in
operator will also be tracked.
Signature:
export declare function reactive<T extends object>(initialValue: T): Store<T>;
Parameters
Parameter | Type | Description |
---|---|---|
initialValue | T | The underlying object |
Returns:
Store<T>
Remarks
When a tracked object is destructed, all tracking information is lost. Instead of destructuring a reactive
object, you need to first convert it with toRefs().
Example
Original object is mutated when the reactive object is mutated.
const originalState = { message: 'hello' };
const state = reactive(originalState);
state.message = 'ciao';
console.log(originalState.message); // => 'ciao'