react-document-title
Declarative, nested, stateful, isomorphic document.title for React
A small React library that lets you set the browser tab title declaratively next to each page component, instead of manually updating document.title throughout your code.
React Document Title: Explaining the Repository
This package solves a common problem in single-page web apps: changing the browser tab title as users navigate between pages. Instead of manually calling JavaScript to update document.title scattered throughout your code, this library lets you declare what the title should be right alongside the page component itself.
Think of it like this: when you're on the home page, you want the tab to say "Home." When you navigate to an article, it should change to the article's title. Normally, you'd have to remember to manually update the browser tab title every time a user lands on a new page. This package automates that by letting you simply wrap each page component and say "when this page is active, use this title." If multiple titles are nested inside each other, the most specific one (the innermost) wins—so you could have an app-wide default like "My Web App" that gets overridden by page-specific titles like "Home" or "Settings."
The library is designed to be lightweight and flexible. It doesn't add any visible elements to your page, works with dynamic titles that update as user state changes, and handles both client-side and server-side rendering. For server-side apps, there's a specific API to retrieve the correct title before sending the HTML to the browser, ensuring search engines and social media get the right page title.
The main tradeoff is scope: this library focuses narrowly on the page title. If you need to manage other HTML metadata—like description tags for social sharing or open graph tags—the README suggests looking at a more comprehensive tool like React Helmet instead.
Where it fits
- Wrap each page component with a DocumentTitle so the browser tab updates automatically on navigation.
- Set an app-wide default title that individual pages override with their own specific title.
- Retrieve the correct title on the server before sending HTML, so search engines see the right page title.
- Update the tab title dynamically as component state changes, like showing an unread message count.