useToRaw
useToRaw is used to retrieve the original object from a reactive proxy object. It is commonly used for debugging, serialization, or interacting with non-reactive tools.
Basic Usage
This scenario demonstrates retrieving the raw object from a proxy and outputting a snapshot of it.
tsx
const source = { settings: { theme: 'dark' } };
const state = useReactive(source);
const raw = useToRaw(state);
console.log(raw); // Original object -> sourceNote: Modifying raw will not trigger reactive rendering.
API
ts
function useToRaw<T extends object>(target: T): T | undefined;Notes
- When called on a reactive proxy, it usually returns the original object.
- When called on a plain object, it may return
undefined. - This hook is mainly used to read the "de-proxied object" and is not intended to drive UI updates.
