fn
useCloned
v0.0.14testeddemoReactive deep clone of a source with a mutable cloned ref, modification tracking, and manual mode.
Examples
ts
const original = ref({ count: 0 });
const { cloned, isModified, sync } = useCloned(original);
cloned.value.count = 1; // isModified.value === true
sync(); // re-clone from source, isModified.value === falsets
const { cloned, sync } = useCloned(source, { manual: true });
// cloned only updates when sync() is calledDemo
Loading demo…
Signature
ts
export function useCloned<T>(
source: MaybeRefOrGetter<T>,
options: UseClonedOptions<T> ={ ... }Type Parameters
TParameters
| Parameter | Type | Description |
|---|---|---|
source | MaybeRefOrGetter<T> | The reactive source to clone (ref, getter, or plain value) |
options? | UseClonedOptions<T> | Options: clone, manual, and watch options (deep, immediate, flush) |
Returns
UseClonedReturn<T>The cloned ref, an isModified flag, and a sync function| Property | Type | Description |
|---|---|---|
cloned | Ref<T> | The cloned, mutable ref. |
isModified | Ref<boolean> | Whether the cloned data has been modified since the last sync. |
sync | () => void | Sync the cloned data with the source manually. |