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/usePrevious.md
1---2category: Utilities3---45# usePrevious67Holds the previous value of a ref.89## Usage1011```ts12import { usePrevious } from '@vueuse/core'13import { shallowRef } from 'vue'1415const counter = shallowRef('Hello')16const previous = usePrevious(counter)1718console.log(previous.value) // undefined1920counter.value = 'World'2122console.log(previous.value) // Hello23```2425## Type Declarations2627```ts28/**29* Holds the previous value of a ref.30*31* @see {@link https://vueuse.org/usePrevious}32*/33export declare function usePrevious<T>(34value: MaybeRefOrGetter<T>,35): Readonly<ShallowRef<T | undefined>>36export declare function usePrevious<T>(37value: MaybeRefOrGetter<T>,38initialValue: T,39): Readonly<ShallowRef<T>>40```41