Skip to content

Latest commit

 

History

History
52 lines (31 loc) · 931 Bytes

index.md

File metadata and controls

52 lines (31 loc) · 931 Bytes
category
Utilities

useCloned

Reactive clone of a ref. By default, it use JSON.parse(JSON.stringify()) to do the clone.

Usage

import { useCloned } from '@vueuse/core'

const original = ref({ key: 'value' })

const { cloned } = useCloned(original)

original.key = 'some new value'

console.log(cloned.value.key) // 'some new value'

Manual cloning

import { useCloned } from '@vueuse/core'

const original = ref({ key: 'value' })

const { cloned, sync } = useCloned(original, { manual: true })

original.key = 'manual'

console.log(cloned.value.key) // 'value'

sync()

console.log(cloned.value.key)// 'manual'

Custom Clone Function

Using klona for example:

import { useCloned } from '@vueuse/core'
import { klona } from 'klona'

const original = ref({ key: 'value' })

const { cloned, sync } = useCloned(original, { clone: klona })