Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
fix(nuxt): allow useHead to accept computed values
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Jul 27, 2022
1 parent f58aa81 commit 9d9de53
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/nuxt/src/head/runtime/composables.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import { isFunction } from '@vue/shared'
import { computed } from 'vue'
import type { ComputedGetter } from '@vue/reactivity'
import type { ComputedGetter, ComputedRef } from '@vue/reactivity'
import type { MetaObject } from '@nuxt/schema'
import { useNuxtApp } from '#app'

type Computable<T> = T extends Record<string, any> ? ComputedGetter<T> | { [K in keyof T]: T[K] | ComputedRef<T[K]> } : T

/**
* You can pass in a meta object, which has keys corresponding to meta tags:
* `title`, `base`, `script`, `style`, `meta` and `link`, as well as `htmlAttrs` and `bodyAttrs`.
*
* Alternatively, for reactive meta state, you can pass in a function
* that returns a meta object.
*/
export function useHead (meta: MetaObject | ComputedGetter<MetaObject>) {
export function useHead (meta: Computable<MetaObject>) {
const resolvedMeta = isFunction(meta) ? computed(meta) : meta
useNuxtApp()._useHead(resolvedMeta)
}

// TODO: remove useMeta support when Nuxt 3 is stable
/** @deprecated Please use new `useHead` composable instead */
export function useMeta (meta: MetaObject | ComputedGetter<MetaObject>) {
export function useMeta (meta: Computable<MetaObject>) {
return useHead(meta)
}

0 comments on commit 9d9de53

Please sign in to comment.