Skip to content

useDocumentTitle

Hook that manages the document title and allows updating it

browser
low
test coverage
Last changed: 8 months ago

TIP

This hook uses document.title browser api to provide enhanced functionality. Make sure to check for compatibility with different browsers when using this api

Installation

Library
CLI
Manual
typescript
import { useDocumentTitle } from '@siberiacancode/reactuse';

Usage

typescript
const { value, set } = useDocumentTitle();

Demo

Api

Parameters

NameTypeDefaultNote
initialValue?string-The initial title. If not provided, the current document title will be used
options.restoreOnUnmount?boolean-Restore the previous title on unmount

Returns

UseDocumentTitleReturn

Type declaration

typescript
export interface UseDocumentTitleOptions {
  /** Restore the previous title on unmount */
  restoreOnUnmount?: boolean;
}

export interface UseDocumentTitleReturn {
  /** The current title */
  value: string;
  /** Function to update the title */
  set: (title: string) => void;
}

Source

SourceDemo

Contributors

D
debabin
debabin
H
hywax
hywax
V
Vitalij Ryndin
Vitalij Ryndin

Released under the MIT License.