Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply VueUse composables in Vue 3/Nuxt projects to replace custom implementations with battle-tested utilities.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/useCached.md
1---2category: Utilities3---45# useCached67Cache a ref with a custom comparator.89## Usage1011```ts12import { useCached } from '@vueuse/core'13import { shallowRef } from 'vue'1415interface Data {16value: number17extra: number18}1920const source = shallowRef<Data>({ value: 42, extra: 0 })21const cached = useCached(source, (a, b) => a.value === b.value)2223source.value = {24value: 42,25extra: 1,26}2728console.log(cached.value) // { value: 42, extra: 0 }2930source.value = {31value: 43,32extra: 1,33}3435console.log(cached.value) // { value: 43, extra: 1 }36```3738## Type Declarations3940```ts41export interface UseCachedOptions<D extends boolean = true>42extends ConfigurableDeepRefs<D>, WatchOptions {}43export declare function useCached<T, D extends boolean = true>(44refValue: Ref<T>,45comparator?: (a: T, b: T) => boolean,46options?: UseCachedOptions<D>,47): UseCachedReturn<T, D>48export type UseCachedReturn<49T = any,50D extends boolean = true,51> = ShallowOrDeepRef<T, D>52```53