1.1.1 • Published 2 years ago

react-use-dom-title-hook v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

react-use-dom-title

Routine Checks Codecov npm

A react hook for handling DOM titles in nested components.

Functionality

The hook adheres to the following rules:

  • It reverts the title when the component unmounts, but only when document.title has the value used by the component
  • The hook listens to the changes of its given value (internally this counts as a new mounted title)
  • When the title changes to an empty string, the hook reverts the title
  • When multiple components with the same title get mounted in a row, the title only gets removed when all components have unmounted
  • When three components get mounted with a title and the second in order unmounts, the title of the first component is secured and loaded when the third component unmounts. Of course this mechanism works with any count of titled components.

Installation

npm i react-use-dom-title-hook or yarn add react-use-dom-title-hook

Demo

You can find a demo here

Code example

import useDOMTitle from "react-use-dom-title-hook";

function MyLoadingComponent() {
  useDOMTitle("Loading...");

  return <Loader />;
}

API Reference

useDOMTitle

useDOMTitle(title: string): void

1.1.1

2 years ago

1.1.0

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago