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/refDefault.md
1---2category: Reactivity3---45# refDefault67Apply default value to a ref.89## Usage1011```ts12import { refDefault, useStorage } from '@vueuse/core'1314const raw = useStorage('key')15const state = refDefault(raw, 'default')1617raw.value = 'hello'18console.log(state.value) // hello1920raw.value = undefined21console.log(state.value) // default22```2324## Type Declarations2526```ts27/**28* Apply default value to a ref.29*30* @__NO_SIDE_EFFECTS__31*/32export declare function refDefault<T>(33source: Ref<T | undefined | null>,34defaultValue: T,35): Ref<T>36```37