Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/joeybaker/react-document-head
- Owner: joeybaker
- License: other
- Created: 2015-06-03T00:06:57.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-06-19T16:28:09.000Z (over 9 years ago)
- Last Synced: 2025-01-04T22:42:25.487Z (11 days ago)
- Language: Shell
- Size: 137 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
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