Skip to content

extendRef

Category
Export Size
207 B
Last Changed
4 months ago

Add extra attributes to Ref.

Usage

Please note the extra attribute will not be accessible in Vue's template.

ts
import { 
extendRef
} from '@vueuse/core'
import {
shallowRef
} from 'vue'
const
myRef
=
shallowRef
('content')
const
extended
=
extendRef
(
myRef
, {
foo
: 'extra data' })
extended
.
value
=== 'content'
extended
.
foo
=== 'extra data'

Refs will be unwrapped and be reactive

ts
const 
myRef
=
shallowRef
('content')
const
extraRef
=
shallowRef
('extra')
const
extended
=
extendRef
(
myRef
, {
extra
:
extraRef
})
extended
.
value
=== 'content'
extended
.
extra
=== 'extra'
extended
.
extra
= 'new data' // will trigger update
extraRef
.
value
=== 'new data'

Type Declarations

ts
export type 
ExtendRefReturn
<
T
= any> =
Ref
<
T
>
export interface
ExtendRefOptions
<
Unwrap
extends boolean = boolean> {
/** * Is the extends properties enumerable * * @default false */
enumerable
?: boolean
/** * Unwrap for Ref properties * * @default true */
unwrap
?:
Unwrap
} /** * Overload 1: Unwrap set to false */ export declare function
extendRef
<
R
extends
Ref
<any>,
Extend
extends object,
Options
extends
ExtendRefOptions
<false>,
>(
ref
:
R
,
extend
:
Extend
,
options
?:
Options
):
ShallowUnwrapRef
<
Extend
> &
R
/** * Overload 2: Unwrap unset or set to true */ export declare function
extendRef
<
R
extends
Ref
<any>,
Extend
extends object,
Options
extends
ExtendRefOptions
,
>(
ref
:
R
,
extend
:
Extend
,
options
?:
Options
):
Extend
&
R

Source

SourceDocs

Contributors

Anthony Fu
SerKo
Robin
IlyaL
Anthony Fu
vaakian X

Changelog

v13.1.0 on
c1d6e - feat(shared): ensure return types exists (#4659)
v12.0.0-beta.1 on
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)
v10.0.0-beta.5 on
13169 - feat(createTemplatePromise): new function (#2957)

Released under the MIT License.

FREE WEEKEND
48 Hours of Unlimited Official Vue.js Certification Training
Reserve Your Spot
23-24 August