# react-document-title

> A declarative, nested, stateful document.title for React

Latest version **2.0.3** (published 2017-04-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-document-title
pnpm add react-document-title
yarn add react-document-title
bun add react-document-title
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.3 |
| Published | 2017-04-12 |
| First published | 2014-10-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/react-document-title) |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1847 |
| Author | Dan Abramov |
| Maintainers | buzinas, gaearon |
| Keywords | react, component, react-component, document.title, title, jsx |

## Links

- npm: https://www.npmjs.com/package/react-document-title
- Repository: https://github.com/gaearon/react-document-title
- Issues: https://github.com/gaearon/react-document-title/issues
- npm.io page: https://npm.io/package/react-document-title

## Dependencies (2)

- [prop-types](https://npm.io/package/prop-types.md) ^15.5.6
- [react-side-effect](https://npm.io/package/react-side-effect.md) ^1.0.2

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 2.0.3 (latest) — 2017-04-12
- 2.0.2 — 2016-06-10
- 2.0.1 — 2015-09-16
- 2.0.0 — 2015-08-27
- 1.0.4 — 2015-08-25
- 1.0.3 — 2015-08-11
- 1.0.2 — 2015-02-22
- 1.0.1 — 2015-02-16
- 1.0.0 — 2015-02-15
- 0.1.3 — 2014-10-30
- 0.1.2 — 2014-10-23
- 0.1.1 — 2014-10-08
- 0.1.0 — 2014-10-08

## README

React Document Title
====================

Provides a declarative way to specify `document.title` in a single-page app.  
This component can be used on server side as well.

Built with [React Side Effect](https://github.com/gaearon/react-side-effect).

====================

## Installation

```
npm install --save react-document-title
```

Dependencies: React >= 0.13.0

## Features

* Does not emit DOM, not even a `<noscript>`;
* Like a normal React compoment, can use its parent's `props` and `state`;
* Can be defined in many places throughout the application;
* Supports arbitrary levels of nesting, so you can define app-wide and page-specific titles;
* Works just as well with isomorphic apps.

## Example

Assuming you use something like [react-router](https://github.com/rackt/react-router):

```javascript
var App = React.createClass({
  render: function () {
    // Use "My Web App" if no child overrides this
    return (
      <DocumentTitle title='My Web App'>
        <this.props.activeRouteHandler />
      </DocumentTitle>
    );
  }
});

var HomePage = React.createClass({
  render: function () {
    // Use "Home" while this component is mounted
    return (
      <DocumentTitle title='Home'>
        <h1>Home, sweet home.</h1>
      </DocumentTitle>
    );
  }
});

var NewArticlePage = React.createClass({
  mixins: [LinkStateMixin],

  render: function () {
    // Update using value from state while this component is mounted
    return (
      <DocumentTitle title={this.state.title || 'Untitled'}>
        <div>
          <h1>New Article</h1>
          <input valueLink={this.linkState('title')} />
        </div>
      </DocumentTitle>
    );
  }
});
```

## Server Usage

If you use it on server, call `DocumentTitle.rewind()` **after rendering components to string** to retrieve the title given to the innermost `DocumentTitle`. You can then embed this title into HTML page template.

Because this component keeps track of mounted instances, **you have to make sure to call `rewind` on server**, or you'll get a memory leak.

## But What About Meta Tags?

Looking for something more powerful? Check out [React Helmet](https://github.com/nfl/react-helmet)!

---
_Source: https://npm.io/package/react-document-title · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
