Skip to content
On this page

useTitle

Reactive Document.title.

Parameters

typescript
import { useTitle } from '@elonehoo/pistachio'

const title = useTitle(newTitle?)
import { useTitle } from '@elonehoo/pistachio'

const title = useTitle(newTitle?)
ParametersTypeRequiredDefaultDescription
newTitlestringfalseundefinedOverrides document.title

State

The useTitle function exposes the following reactive state:

typescript
import { useTitle } from '@elonehoo/pistachio'

const title = useTitle()
import { useTitle } from '@elonehoo/pistachio'

const title = useTitle()
StateTypeDescription
titleRef<string>Ref for document.title, watches for document.title changes or set to update the title

Example

vue
<script setup lang="ts">
import { useTitle } from '@elonehoo/pistachio'

const title = useTitle()
</script>

<template>
  <div>
    <label for="title-updater">document.title:</label>
    <input name="title-updater" v-model="title" />
  </div>
</template>
<script setup lang="ts">
import { useTitle } from '@elonehoo/pistachio'

const title = useTitle()
</script>

<template>
  <div>
    <label for="title-updater">document.title:</label>
    <input name="title-updater" v-model="title" />
  </div>
</template>

Released under the MIT License.