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/extendRef.md
1---2category: Reactivity3---45# extendRef67Add extra attributes to Ref.89## Usage1011> Please note the extra attribute will not be accessible in Vue's template.1213```ts14import { extendRef } from '@vueuse/core'15import { shallowRef } from 'vue'1617const myRef = shallowRef('content')1819const extended = extendRef(myRef, { foo: 'extra data' })2021extended.value === 'content'22extended.foo === 'extra data'23```2425Refs will be unwrapped and be reactive2627```ts28import { extendRef } from '@vueuse/core'29// ---cut---30const myRef = shallowRef('content')31const extraRef = shallowRef('extra')3233const extended = extendRef(myRef, { extra: extraRef })3435extended.value === 'content'36extended.extra === 'extra'3738extended.extra = 'new data' // will trigger update39extraRef.value === 'new data'40```4142## Type Declarations4344```ts45export type ExtendRefReturn<T = any> = Ref<T>46export interface ExtendRefOptions<Unwrap extends boolean = boolean> {47/**48* Is the extends properties enumerable49*50* @default false51*/52enumerable?: boolean53/**54* Unwrap for Ref properties55*56* @default true57*/58unwrap?: Unwrap59}60/**61* Overload 1: Unwrap set to false62*/63export declare function extendRef<64R extends Ref<any>,65Extend extends object,66Options extends ExtendRefOptions<false>,67>(ref: R, extend: Extend, options?: Options): ShallowUnwrapRef<Extend> & R68/**69* Overload 2: Unwrap unset or set to true70*/71export declare function extendRef<72R extends Ref<any>,73Extend extends object,74Options extends ExtendRefOptions,75>(ref: R, extend: Extend, options?: Options): Extend & R76```77