packages/core/useCloned/index.md
Reactive clone of a ref. By default, it use JSON.parse(JSON.stringify()) to do the clone.
import { useCloned } from '@vueuse/core'
const original = ref({ key: 'value' })
const { cloned } = useCloned(original)
original.value.key = 'some new value'
console.log(cloned.value.key) // 'value'
Changes to the source are not reflected in the cloned ref immediately.
Use { flush: 'sync' } to obtain the updated value without delay.
const { cloned } = useCloned(original, { flush: 'sync' })
original.value.key = 'some new value'
console.log(cloned.value.key) // 'some new value'
import { useCloned } from '@vueuse/core'
const original = ref({ key: 'value' })
const { cloned, sync } = useCloned(original, { manual: true })
original.value.key = 'manual'
console.log(cloned.value.key) // 'value'
sync()
console.log(cloned.value.key)// 'manual'
Using klona for example:
import { useCloned } from '@vueuse/core'
import { klona } from 'klona'
const original = ref({ key: 'value' })
const { cloned, isModified, sync } = useCloned(original, { clone: klona })