Skip to content

createRef

Category
Export Size
113 B
Last Changed
2 weeks ago

Returns a deepRef or shallowRef depending on the deep param.

Usage

ts
import { 
createRef
} from '@vueuse/core'
import {
isShallow
,
ref
} from 'vue'
const
initialData
= 1
const
shallowData
=
createRef
(
initialData
)
const
deepData
=
createRef
(
initialData
, true)
isShallow
(
shallowData
) // true
isShallow
(
deepData
) // false
js
import { createRef } from '@vueuse/core'
import { isShallow } from 'vue'
const initialData = 1
const shallowData = createRef(initialData)
const deepData = createRef(initialData, true)
isShallow(shallowData) // true
isShallow(deepData) // false

Type Declarations

ts
export type 
CreateRefReturn
<
T
= any,
D
extends boolean = false,
> =
ShallowOrDeepRef
<
T
,
D
>
export type
ShallowOrDeepRef
<
T
= any,
D
extends boolean = false,
> =
D
extends true ?
Ref
<
T
> :
ShallowRef
<
T
>
/** * Returns a `deepRef` or `shallowRef` depending on the `deep` param. * * @example createRef(1) // ShallowRef<number> * @example createRef(1, false) // ShallowRef<number> * @example createRef(1, true) // Ref<number> * @example createRef("string") // ShallowRef<string> * @example createRef<"A"|"B">("A", true) // Ref<"A"|"B"> * * @param value * @param deep * @returns the `deepRef` or `shallowRef` * * @__NO_SIDE_EFFECTS__ */ export declare function
createRef
<
T
= any,
D
extends boolean = false>(
value
:
T
,
deep
?:
D
,
):
CreateRefReturn
<
T
,
D
>

Source

SourceDocs

Contributors

Robin
SerKo

Changelog

v13.6.0 on
d32f8 - refactor: add @__NO_SIDE_EFFECTS__ annotations to all pure functions (#4907)
v13.1.0 on
c1d6e - feat(shared): ensure return types exists (#4659)
v12.8.0 on
9afee - feat(useCached): add options.deepRefs (#4591)

Released under the MIT License.

Build faster with AI
New Masterclass to help you leverage AI in your Vue workflow
Get Early Access