R
fn

useCloned

v0.0.15testeddemo

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