Skip to content

toRef

Category
Export Size
181 B
Last Changed
4 days ago
Alias
resolveRef
Related

Normalize value/ref/getter to ref or computed.

Usage

ts
import { 
toRef
} from '@vueuse/core'
const
foo
=
ref
('hi')
const
a
=
toRef
(0) // Ref<number>
const
b
=
toRef
(
foo
) // Ref<string>
const
c
=
toRef
(() => 'hi') // ComputedRef<string>

Type Declarations

ts
/**
 * Normalize value/ref/getter to `ref` or `computed`.
 */
export declare function 
toRef
<
T
>(
r
: () =>
T
):
Readonly
<
Ref
<
T
>>
export declare function
toRef
<
T
>(
r
:
ComputedRef
<
T
>):
ComputedRef
<
T
>
export declare function
toRef
<
T
>(
r
:
MaybeRefOrGetter
<
T
>):
Ref
<
T
>
export declare function
toRef
<
T
>(
r
:
T
):
Ref
<
T
>
export declare function
toRef
<
T
extends object,
K
extends keyof
T
>(
object
:
T
,
key
:
K
,
):
ToRef
<
T
[
K
]>
export declare function
toRef
<
T
extends object,
K
extends keyof
T
>(
object
:
T
,
key
:
K
,
defaultValue
:
T
[
K
],
):
ToRef
<
Exclude
<
T
[
K
], undefined>>
/** * @deprecated use `toRef` instead */ export declare const
resolveRef
: typeof
toRef

Source

SourceDocs

Contributors

NoiseFan

Changelog

No recent changes

Released under the MIT License.