Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/joeybaker/react-document-head

Simple function to isomorphically set the <title> on the server and the client in a React workflow.
https://github.com/joeybaker/react-document-head

Last synced: 6 days ago
JSON representation

Simple function to isomorphically set the <title> on the server and the client in a React workflow.

Awesome Lists containing this project

README

        

# #####
# Deprecated. Use [react-helmet](https://github.com/nfl/react-helmet) instead
# #####

# react-document-head [![NPM version][npm-image]][npm-url] [![Dependency Status][daviddm-url]][daviddm-image] [![Build Status][travis-image]][travis-url]

Simple function to isomorphically set the <title> on the server and the client in a React workflow.

**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*

- [Install](#install)
- [Usage](#usage)
- [Options](#options)
- [`` title](#string-title)
- [Tests](#tests)
- [Developing](#developing)
- [Requirements](#requirements)
- [License](#license)

## Install

```sh
npm i -S react-document-head
```

## Usage

A React component
```js
import setHead from 'react-document-head'
import React from 'react'

export default class SingleDiv extends React.Component {
render () {
setHead({title: 'my title'})
return


}
}
```

On the server…
```js
const content = React.renderToString(SingleDiv)
const title = React.documentHead.title
const html = `

${title}




`

reply(html)
```

## Options
### `` title
Set the title. On the client, this sets `document.title`, on the server, it sets a global: `React.documentHead`.

## Tests
Tests are in [tape](https://github.com/substack/tape).

* `npm test` will run both server and browser tests
* `npm run test-browser` and `npm run test-server` run their respective tests
* `npm run tdd-server` will run the server tests on every file change.
* `npm run tdd-browser` will run the browser tests on every file change.

## Developing
To publish, run `npm run release -- [{patch,minor,major}]`

_NOTE: you might need to `sudo ln -s /usr/local/bin/node /usr/bin/node` to ensure node is in your path for the git hooks to work_

### Requirements
* **npm > 2.0.0** So that passing args to a npm script will work. `npm i -g npm`
* **git > 1.8.3** So that `git push --follow-tags` will work. `brew install git`

## License

Artistic 2.0 © [Joey Baker](http://byjoeybaker.com)

[npm-url]: https://npmjs.org/package/react-document-head
[npm-image]: https://badge.fury.io/js/react-document-head.svg
[travis-url]: https://travis-ci.org/joeybaker/react-document-head
[travis-image]: https://travis-ci.org/joeybaker/react-document-head.svg?branch=master
[daviddm-url]: https://david-dm.org/joeybaker/react-document-head.svg?theme=shields.io
[daviddm-image]: https://david-dm.org/joeybaker/react-document-head