feat: dynamic page titles across SPA
useDocumentTitle hook sets document.title per page. Dynamic: movie name, person name, username, wrapup year. Static: diary, profile, search, social, all settings pages.
This commit is contained in:
12
spa/src/hooks/use-document-title.ts
Normal file
12
spa/src/hooks/use-document-title.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { useEffect } from "react"
|
||||
|
||||
const BASE_TITLE = "Movies Diary"
|
||||
|
||||
export function useDocumentTitle(title?: string) {
|
||||
useEffect(() => {
|
||||
document.title = title ? `${title} — ${BASE_TITLE}` : BASE_TITLE
|
||||
return () => {
|
||||
document.title = BASE_TITLE
|
||||
}
|
||||
}, [title])
|
||||
}
|
||||
Reference in New Issue
Block a user