Skip to Content
ohooks

useDocumentTitle

Updates document.title reactively and optionally restores the original title on unmount.

Loading preview...

The useDocumentTitle hook synchronizes document.title with a string value and can restore the previous title when the component unmounts.

Installation

pnpm dlx shadcn@latest add https://ohooks.vercel.app/r/useDocumentTitle.json

Usage

Examples

Dynamic Notification Badge in Title

Include live state in the title string to reflect unread counts or background task status in the browser tab.

Restoring the Previous Title on Unmount

Enable restoreOnUnmount: true inside modals, drawers, or temporary views so closing them restores the parent page's title.

API Reference

UseDocumentTitleOptions

Configuration options for useDocumentTitle.

Property
Specification
restoreOnUnmount?
uniondefault:false
Restore the previous document.title when the component unmounts