Join our Discord Community

useDocumentTitle

Dynamic document title management for React applications. Perfect for Next.js projects requiring browser tab updates with TypeScript support and seamless integration.

Loading component...

Installation

npx shadcn@latest add https://www.shadcn.io/registry/use-document-title.json
npx shadcn@latest add https://www.shadcn.io/registry/use-document-title.json
pnpm dlx shadcn@latest add https://www.shadcn.io/registry/use-document-title.json
bunx shadcn@latest add https://www.shadcn.io/registry/use-document-title.json

Features

  • Real-time title updates with automatic DOM synchronization using React useEffect
  • TypeScript support with complete interface definitions and IntelliSense
  • Lightweight implementation with zero external dependencies beyond React
  • SSR compatibility designed for Next.js server-side rendering environments
  • Memory efficient with automatic cleanup and dependency optimization
  • shadcn/ui integration compatible with existing design system components

Examples

Dynamic App State

Loading component...

Demonstrates advanced usage with notification counts, user status, and tab switching for complex application states.

Use Cases

This free open source React hook works well for:

  • Dashboard applications - Real-time notification counts built with Next.js and TypeScript
  • Chat interfaces - Unread message indicators using React state management
  • Task management - Progress indicators with Tailwind CSS styling integration
  • E-commerce sites - Cart item counts with seamless shadcn/ui compatibility
  • Admin panels - Status updates and alerts for JavaScript-based interfaces

API Reference

useDocumentTitle

PropTypeDefaultDescription
titlestringrequiredThe title text to set for the document

Implementation Notes

  • Hook executes on every title change using React's useEffect dependency array
  • Document title updates are batched with React's rendering cycle for optimal performance
  • Compatible with all modern browsers and Next.js deployment environments
  • Automatically handles string sanitization and special character encoding
  • Works seamlessly with React Strict Mode and development hot reloading