use-document-title
Bind the document title to reactive state.
| Package | @vizejs/composable/use-document-title |
| Own the source | vize lib pull composable:use-document-title |
| Runtime exports | useDocumentTitle |
| Gzip budget | 2304 B |
Usage
import { useDocumentTitle } from "@vizejs/composable/use-document-title";
Runtime contract
| Utility | Category | Stability | SSR | Hydration | Cleanup | Targets | Host globals | Uses |
|---|---|---|---|---|---|---|---|---|
useDocumentTitle |
dom | experimental | deterministic-fallback | caller-managed | reactive-scope | web, desktop | window |
tryOnScopeDispose, useMounted |
API
useDocumentTitle
Bind the document title to reactive state. Accepts a writable ref (used as-is), a getter (followed), a plain string, or nothing (an owned ref seeded from the current title). Every non-nullish title is passed through template before it is written. With observe, external title changes flow back into title. Server rendering: the document is never touched and title keeps the value it was given (or undefined). Head management for server-rendered markup (<title> in the HTML) is the job of the application's head manager; this composable only updates the live document on the client. Watchers and the observer are released with the owning reactive scope, which also applies restoreOnDispose.
function useDocumentTitle( title?: MaybeRefOrGetter<string | null | undefined>, options: UseDocumentTitleOptions = {}, ): DocumentTitleControls
const { title } = useDocumentTitle(() => route.meta.title, { template: "%s | Vize" });
Types
DocumentTitleHost
Document subset used by useDocumentTitle.
| Member | Type | Description |
|---|---|---|
title |
string |
Current document title (readable and writable). |
observeTitle? |
(callback: () => void) => () => void |
Observe external title changes (for example by other libraries). Returns a function that stops observing. |
UseDocumentTitleOptions
Options for useDocumentTitle.
| Member | Type | Description |
|---|---|---|
template? |
DocumentTitleTemplate |
Template applied to every title written to the document. |
restoreOnDispose? |
DocumentTitleRestore |
Title restored when the owning reactive scope stops: false leaves the current title, "previous" restores the title seen at creation, and a function computes it. |
observe? |
boolean |
Follow title changes made outside this composable. |
host? |
MaybeRefOrGetter<DocumentTitleHost | null | undefined> |
Document capability for alternate runtimes and tests. |
DocumentTitleControls
Reactive state returned by useDocumentTitle.
| Member | Type | Description |
|---|---|---|
title |
Ref<string | null | undefined> |
Title before templating. Writable; null/undefined leaves the document title untouched. When a getter was passed, the next getter change overwrites manual assignments. |
supported |
ComputedRef<boolean> |
Whether a document capability is attached. Inside a component it stays false until mounted, so hydration matches the server render. |