fn

useCloned

v0.0.14testeddemo

Reactive 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 === false
ts
const { cloned, sync } = useCloned(source, { manual: true });
// cloned only updates when sync() is called

Demo

Loading demo…

Signature

ts
export function useCloned<T>(
  source: MaybeRefOrGetter<T>,
  options: UseClonedOptions<T> ={ ... }

Type Parameters

T

Parameters

ParameterTypeDescription
sourceMaybeRefOrGetter<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
PropertyTypeDescription
clonedRef<T>The cloned, mutable ref.
isModifiedRef<boolean>Whether the cloned data has been modified since the last sync.
sync() => voidSync the cloned data with the source manually.