module author Surmon <https://github.com/surmon-china>
  import { useState as useReactState } from 'react' ; import { useWatch } from './watch' ; import { useForceUpdate } from './utils' ; import type { ToRef } from './reactivity' ; import { ref as vRef , shallowRef as vShallowRef , reactive as vReactive , shallowReactive as vShallowReactive , computed as vComputed , ComputedGetter , Ref , UnwrapRef , UnwrapNestedRefs , DebuggerOptions , ComputedRef , WritableComputedOptions , WritableComputedRef , } from '@vue/reactivity' ; /** ref hook */ export function useRef < T extends object > ( value ) ; export function useRef < T > ( value ) ; export function useRef < T = any > ( initValue ? ) { const [ value ] = useReactState ( ( ) => vRef ( initValue ) ) ; const forceUpdate = useForceUpdate ( ) ; useWatch ( value , forceUpdate ) ; return value as unknown as any ; } /** shallowRef hook */ export function useShallowRef < T extends object > ( value ) ; export function useShallowRef < T > ( value ) ; export function useShallowRef < T = any > ( initValue ) { const [ value ] = useReactState ( ( ) => vShallowRef ( initValue ) ) ; const forceUpdate = useForceUpdate ( ) ; useWatch ( value , forceUpdate ) ; return value ; } /** reactive hook */ export function useReactive < T extends object > ( target ) { const [ value ] = useReactState ( ( ) => vReactive ( target ) ) ; const forceUpdate = useForceUpdate ( ) ; useWatch ( value , forceUpdate ) ; return value ; } /** shallowReactive hook */ export function useShallowReactive < T extends object > ( target ) { const [ value ] = useReactState ( ( ) => vShallowReactive ( target ) ) ; const forceUpdate = useForceUpdate ( ) ; useWatch ( value , forceUpdate ) ; return value ; } /** computed hook */ export function useComputed < T > ( options , debugOptions ? ) ; export function useComputed < T > ( getter , debugOptions ? ) ; export function useComputed ( arg1 , arg2 ) { const [ value ] = useReactState ( ( ) => vComputed ( arg1 , arg2 ) ) ; const forceUpdate = useForceUpdate ( ) ; useWatch ( value , forceUpdate ) ; return value ; } /** any data to reactivity */ export function useReactivity < T = any > ( getter ) { const forceUpdate = useForceUpdate ( ) ; useWatch ( ( ) => getter ( ) , forceUpdate , { deep : true } ) ; return getter ( ) ; }