import { Ref , toRefs , computed , watch , ComputedRef } from 'vue' ; import { isUndefined } from '../_utils/is' ; import useState from './use-state' ; export default function useMergeState < T , E = T | undefined > ( defaultValue , props ) { const { value } = toRefs ( props ) ; const [ localValue , setLocalValue ] = useState ( ! isUndefined ( value . value ) ? value . value : defaultValue ) ; watch ( value , ( newVal ) => { isUndefined ( newVal ) && setLocalValue ( undefined ) ; } ) ; const mergeValue = computed ( ( ) => ! isUndefined ( value . value ) ? value . value : localValue . value ) ; return [ mergeValue , setLocalValue , localValue ] ; }