Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply VueUse composables in Vue 3/Nuxt projects to replace custom implementations with battle-tested utilities.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/createRef.md
1---2category: Reactivity3---45# createRef67Returns a `deepRef` or `shallowRef` depending on the `deep` param.89## Usage1011```ts12import { createRef } from '@vueuse/core'13import { isShallow, ref } from 'vue'1415const initialData = 11617const shallowData = createRef(initialData)18const deepData = createRef(initialData, true)1920isShallow(shallowData) // true21isShallow(deepData) // false22```2324## Type Declarations2526```ts27export type CreateRefReturn<28T = any,29D extends boolean = false,30> = ShallowOrDeepRef<T, D>31export type ShallowOrDeepRef<32T = any,33D extends boolean = false,34> = D extends true ? Ref<T> : ShallowRef<T>35/**36* Returns a `deepRef` or `shallowRef` depending on the `deep` param.37*38* @example createRef(1) // ShallowRef<number>39* @example createRef(1, false) // ShallowRef<number>40* @example createRef(1, true) // Ref<number>41* @example createRef("string") // ShallowRef<string>42* @example createRef<"A"|"B">("A", true) // Ref<"A"|"B">43*44* @param value45* @param deep46* @returns the `deepRef` or `shallowRef`47*48* @__NO_SIDE_EFFECTS__49*/50export declare function createRef<T = any, D extends boolean = false>(51value: T,52deep?: D,53): CreateRefReturn<T, D>54```55