Skip to content

toRef ​

Category
Export Size
159 B
Last Changed
5 months 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>
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>

Source ​

Source • Docs

Contributors ​

Anthony Fu

Changelog ​

v10.0.0 on 4/14/2023
cb6f9 - fix: improve types overload, close #2925
v10.0.0-beta.4 on 4/13/2023
4d757 - feat(types)!: rename MaybeComputedRef to MaybeRefOrGetter
f307f - feat: support two argument overrides from Vue
10e98 - feat!: rename resolveRef to toRef
v8.9.1 on 7/8/2022
a9ccc - feat(all): use MaybeComputedRef (#1768)
v8.8.0 on 7/6/2022
29fd5 - feat(resolveRef): new function (#1743)

Released under the MIT License.