4
4
*/
5
5
6
6
import { useState as useReactState } from 'react'
7
+ import { ref as vueRef , shallowRef as vueShallowRef , customRef as vueCustomRef } from '@vue/reactivity'
8
+ import type { Ref , UnwrapRef , ShallowRef , CustomRefFactory } from '@vue/reactivity'
7
9
import { useForceUpdate , IfAny } from './_utils'
8
10
import { useWatch } from './watch'
9
- import { ref as vRef , shallowRef as vShallowRef , customRef as vCustomRef } from '@vue/reactivity'
10
- import type { Ref , UnwrapRef , ShallowRef , CustomRefFactory } from '@vue/reactivity'
11
11
12
12
/**
13
13
* Takes an inner value and returns a reactive and mutable ref object, which
@@ -30,10 +30,10 @@ export function useRef<T>(
30
30
) : [ T ] extends [ Ref ] ? IfAny < T , Ref < T > , T > : Ref < UnwrapRef < T > , UnwrapRef < T > | T >
31
31
export function useRef < T = any > ( ) : Ref < T | undefined >
32
32
export function useRef ( initValue ?: unknown ) {
33
- const [ refObj ] = useReactState ( ( ) => vRef ( initValue ) )
33
+ const [ refObject ] = useReactState ( ( ) => vueRef ( initValue ) )
34
34
const forceUpdate = useForceUpdate ( )
35
- useWatch ( refObj , forceUpdate , { deep : true } )
36
- return refObj as unknown as any
35
+ useWatch ( refObject , forceUpdate , { deep : true } )
36
+ return refObject as unknown as any
37
37
}
38
38
39
39
/**
@@ -56,10 +56,10 @@ export function useShallowRef<T>(
56
56
) : Ref extends T ? ( T extends Ref ? IfAny < T , ShallowRef < T > , T > : ShallowRef < T > ) : ShallowRef < T >
57
57
export function useShallowRef < T = any > ( ) : ShallowRef < T | undefined >
58
58
export function useShallowRef ( initValue ?: unknown ) {
59
- const [ sRefObj ] = useReactState ( ( ) => vShallowRef ( initValue ) )
59
+ const [ shallowRefObject ] = useReactState ( ( ) => vueShallowRef ( initValue ) )
60
60
const forceUpdate = useForceUpdate ( )
61
- useWatch ( sRefObj , forceUpdate )
62
- return sRefObj
61
+ useWatch ( shallowRefObject , forceUpdate )
62
+ return shallowRefObject
63
63
}
64
64
65
65
/**
@@ -70,8 +70,8 @@ export function useShallowRef(initValue?: unknown) {
70
70
* @see {@link https://vuejs.org/api/reactivity-advanced.html#customref Vue `customRef()` }
71
71
*/
72
72
export function useCustomRef < T > ( factory : CustomRefFactory < T > ) : Ref < T > {
73
- const [ cRefObj ] = useReactState ( ( ) => vCustomRef ( factory ) )
73
+ const [ customRefObject ] = useReactState ( ( ) => vueCustomRef ( factory ) )
74
74
const forceUpdate = useForceUpdate ( )
75
- useWatch ( cRefObj , forceUpdate )
76
- return cRefObj
75
+ useWatch ( customRefObject , forceUpdate )
76
+ return customRefObject
77
77
}
0 commit comments