Skip to content

Repository files navigation

react-use-title

A lightweight and customizable React hook for managing document titles with support for prefixes, suffixes, custom separators, title restoration, and page visibility changes.

Recat TS npm

Features

  • πŸš€ Lightweight and easy to use
  • βš›οΈ Built for React 18 and React 19
  • πŸ“ Set the document title with a simple API
  • πŸ”– Add custom prefixes and suffixes
  • ✨ Customize the separator between title parts
  • πŸ”„ Restore the previous title on unmount
  • πŸ‘€ Change the title when the page becomes hidden
  • πŸ’™ Fully written in TypeScript

Installation

npm install react-use-title

Usage

1. Basic:

GIF_20260729_125010_732
export default function App() {
  useTitle("Dashboard")
  return <h1>react-use-title</h1>;
}

Preview

Screenshot (506)



2. Prefix:

GIF_20260729_125850_599
export default function App() {
  useTitle("Dashboard",{
    prefix:"Admin"
  })
  return <h1>react-use-title</h1>;
}

Preview

Screenshot (505)



3. Suffix:

GIF_20260729_125449_332
export default function App() {
  useTitle("Dashboard",{
    suffix:"My App"
  })
  return <h1>react-use-title</h1>;
}

Preview

Screenshot (504)



4. separator

GIF_20260729_130203_098
export default function App() {
  useTitle("Dashboard",{
    prefix:"Admin",
    suffix:"My App",
    separator:"😍"
  })
  return <h1>react-use-title</h1>;
}

Preview

Default

Screenshot (507)

Using Separator

Screenshot (502)



5. onHidden

GIF_20260729_130553_092
export default function App() {
  useTitle("Dashboard",{
    prefix:"Admin",
    suffix:"My App",
    separator:"😍",
    onHidden:{title:"Why Did You Leave? 😐"}
  })
  return <h1>react-use-title</h1>;
}

Preview

Note: GIF may take a few seconds to load.

GIF_20260729_172801_244

API

useTitle

useTitle(title: string, options?: UseTitleOptions): void

Parameters

Parameter Type Description
title string The document title.
options UseTitleOptions Optional configuration object.

UseTitleOptions

Option Type Default Description
prefix string undefined Adds text before the title.
suffix string undefined Adds text after the title.
separator string "|" (Pipe) Separator between title parts.
restoreOnUnmount boolean false Restores the previous document title when the component unmounts.
onHidden { title: string } undefined Changes the document title when the page becomes hidden.

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

A lightweight and customizable React hook for managing document titles.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages