import type { Ref, WatchOptions } from '@mpxjs/core' import { ref, watch } from '@mpxjs/core' export function useCached( refValue: Ref, comparator: (a: T, b: T) => boolean = (a, b) => a === b, watchOptions?: WatchOptions ): Ref { const cachedValue = ref(refValue.value) as Ref watch(() => refValue.value, (value) => { if (!comparator(value, cachedValue.value)) cachedValue.value = value }, watchOptions) return cachedValue }