An open API service indexing awesome lists of open source software.

https://github.com/tajo/react-titled

📃 Set document.title with ease. Nested. Flexible.
https://github.com/tajo/react-titled

Last synced: 29 days ago
JSON representation

📃 Set document.title with ease. Nested. Flexible.

Awesome Lists containing this project

README

          

# React-titled

[![npm version](https://img.shields.io/npm/v/react-titled.svg?style=flat-square)](https://www.npmjs.com/package/react-titled)
[![npm downloads](https://img.shields.io/npm/dm/react-titled.svg?style=flat-square)](https://www.npmjs.com/package/react-titled)
[![Build Status](https://github.com/tajo/react-titled/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/tajo/react-titled/actions/workflows/ci.yml)

> To fully control document.title in your React app.

## Features

* **requires React v16.8+**
* **supports nesting, similar to react-router**
* updates `document.title` only when all react-titled instances are reconciled
* flexible, it lets you to specify how different levels should be concatenated
* **no dependencies**, ~100 lines of code

## Installation

```shell
yarn add react react-dom react-titled
```

## Usage examples

### Basic

```jsx
import { Titled } from 'react-titled';

Welcome!


`Homepage | ${title}`} />
;
```

outputs

```
Homepage | Example.com
```

### The deepest one wins

```jsx
import { Titled } from 'react-titled';

'Example.com'}>
'Homepage'} />
;
```

outputs

```
Homepage
```

### Subscribe to changes

```jsx
import { Titled } from 'react-titled';

'Example.com'} onChange={title => console.log(title)}>

Welcome!


`Homepage | ${title}`} />
;
```

## Run Examples

```shell
git clone https://github.com/tajo/react-titled
cd react-titled
yarn install
yarn build:examples
open examples/index.html
```

## Contributions Welcome!

```shell
git clone https://github.com/tajo/react-titled
cd react-titled
yarn install
yarn build:examples --watch
open examples/index.html
```

### Run Tests

```
yarn test
```

## Author

Vojtech Miksu 2018, [miksu.cz](https://miksu.cz), [@vmiksu](https://twitter.com/vmiksu)