// Easily update page title dynamically
const { setTitle, restoreTitle } = useDocumentTitle('My App');
Perfect for SEO optimization, user notifications, progress indicators, or any dynamic page title management.
Pro tip:
Look at your browser tab to see the title changes! Perfect for notifications, progress indicators, or SEO optimization.
import { useDocumentTitle } from '@usegrand/react-hokss'; function NotificationApp() { const { setTitle, setTitleWithTemplate, addPrefix, restoreTitle } = useDocumentTitle( 'My App', { template: '{title} - My Company', restoreOnUnmount: true } ); const showNotification = () => { setTitle('🔔 New Message!'); setTimeout(() => { setTitle('My App'); }, 3000); }; const showProgress = (progress: number) => { setTitleWithTemplate(`Loading... ${progress}%`); }; return ( <div> <button onClick={showNotification}> Show Notification </button> <button onClick={() => showProgress(75)}> Show Progress </button> <button onClick={restoreTitle}> Restore Title </button> </div> ); }
Initial title to set (optional)
Configuration options for title management
Whether to restore original title on unmount (default: true)
Template string with {title} placeholder
Prefix to add before the title
Suffix to add after the title
Object containing title control functions
Function to set the document title
Function to get the current document title
Function to restore the original title
Function to add a prefix to the current title
Function to add a suffix to the current title
Function to set title using template