Skip to content

⬅️ Back to Table of Contents

📄 refDefault

📊 Analysis Summary

Metric Count
🔧 Functions 1
📦 Imports 2
🟢 Vue Composition API 1

📚 Table of Contents

🛠️ File Location:

📂 packages/shared/refDefault/index.ts

📦 Imports

Name Source
Ref vue
computed vue

Vue Composition API

Name Type Reactive Variables Composables
computed computed none none

Functions

refDefault(source: Ref<T | undefined | null>, defaultValue: T): Ref<T>

Apply default value to a ref.

Tags: @__NO_SIDE_EFFECTS__

Raw JSDoc
/**
 * Apply default value to a ref.
 *
 * @__NO_SIDE_EFFECTS__
 */

Calls:

  • computed (from vue)
Code
export function refDefault<T>(source: Ref<T | undefined | null>, defaultValue: T): Ref<T> {
  return computed({
    get() {
      return source.value ?? defaultValue
    },
    set(value) {
      source.value = value
    },
  })
}

Generated by Syntax Scribe