BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/zyeon/use-document-title

useDocumentTitle

zyeon/use-document-title
FreeHook

Sets document.title for as long as a component is mounted and restores the pre-mount title on unmount.

Install it

npx shadcn@latest add https://ui.zyeon.ai/r/use-document-title.json

Source

src/registry/hooks/use-document-title.tsxui.zyeon.ai/r/use-document-title.json
1"use client"
2
3import * as React from "react"
4
5export interface UseDocumentTitleOptions {
6 /** Restore `document.title` to the snapshot taken at mount when unmounting. Defaults to `true`. */
7 restoreOnUnmount?: boolean
8}
9
10/**
11 * Sets `document.title` to `title` and keeps it in sync on every change. At mount
12 * the title as it stands **at that instant** is snapshotted into a ref; at unmount
13 * it is restored from that snapshot when `restoreOnUnmount` (default `true`), and
14 * left at the last title this hook wrote when `false`.
15 *
16 * `document` is only read and written inside effects — never during render or on
17 * the server — so the hook is safe in server-rendered components.
18 *
19 * Nested instances (say a route layout and a page component that both call it):
20 * each instance only remembers the title that was on the page when *it* mounted,
21 * and knows nothing about the others. Mount order decides what you see — the one
22 * that mounts last writes `document.title` last, so it wins. But if unmount order
23 * isn't strictly last-in-first-out (an outer instance unmounting before an inner
24 * one), the snapshot the outer instance restores is older than the title the inner
25 * one set, and the title "jumps back" further than expected instead of to the
26 * enclosing title. That is deliberate, simplified semantics, not a bug — when you
27 * genuinely need strict restore ordering across levels, use one shared title stack
28 * rather than several independent hook instances (see Customization levers in the
29 * docs).
30 */
31export function useDocumentTitle(
32 title: string,
33 options: UseDocumentTitleOptions = {},
34): void {
35 const { restoreOnUnmount = true } = options
36 const restoreOnUnmountRef = React.useRef(restoreOnUnmount)
37 const previousTitleRef = React.useRef<string | null>(null)
38
39 // Keep restoreOnUnmountRef on the latest option — the unmount cleanup runs once
40 // and must read the current value, not the one closed over at mount.
41 React.useEffect(() => {
42 restoreOnUnmountRef.current = restoreOnUnmount
43 }, [restoreOnUnmount])
44
45 // Snapshot the title at mount and restore it at unmount; empty deps so it fires
46 // once on a real mount/unmount instead of re-snapshotting on every title change.
47 React.useEffect(() => {
48 previousTitleRef.current = document.title
49 return () => {
50 if (restoreOnUnmountRef.current && previousTitleRef.current !== null) {
51 document.title = previousTitleRef.current
52 }
53 }
54 }, [])
55
56 React.useEffect(() => {
57// … truncated

Files it writes

  • src/registry/hooks/use-document-title.tsx

Facts

Registry
zyeon
Type
registry:hook
Access
Free
Files written
1
Licence
MIT
In the index
at or before 2026-08-13
Last confirmed
yesterday

Go to the source

ui.zyeon.ai Zyeon-AI/zyeon-ui-components on GitHub Raw registry item This item as JSON

More from zyeon

All 893 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
useAsyncuse-asynczyeonHooksFreeno deps
useBatteryuse-batteryzyeonHooksFreeno deps
useBroadcastChanneluse-broadcast-channelzyeonHooksFreeno deps
useClickOutsideuse-click-outsidezyeonHooksFreeno deps
useClipboardPasteuse-clipboard-pastezyeonHooksFreeno deps
useControllableStateuse-controllable-statezyeonHooksFreeno deps
useCookieuse-cookiezyeonHooksFreeno deps
useCopyToClipboarduse-copy-to-clipboardzyeonHooksFreeno deps

Also from Kynth Studios

Built for the same person as BlockDex

SkillWorks

Claude Code skills and plugins, scored

skillworks.kynth.studio

RuleStack

AGENTS.md gallery and agent-config comparison

rulestack.kynth.studio

KitGrade

SaaS starter kits, scored from measured facts

kitgrade.kynth.studio

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and KitGrade

part of Toolproof, the measurement layer for AI agent tooling

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and KitGrade

part of Toolproof, the measurement layer for AI agent tooling

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and KitGrade

part of Toolproof, the measurement layer for AI agent tooling

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex