1.0.1 • Published 10 years ago
react-document-head v1.0.1
Deprecated. Use react-helmet instead
react-document-head

Simple function to isomorphically set the <title> on the server and the client in a React workflow.
Table of Contents generated with DocToc
Install
npm i -S react-document-headUsage
A React component
import setHead from 'react-document-head'
import React from 'react'
export default class SingleDiv extends React.Component {
render () {
setHead({title: 'my title'})
return <div />
}
}On the server…
const content = React.renderToString(SingleDiv)
const title = React.documentHead.title
const html = `<html>
<head>
<title>${title}</title>
</head>
<body>
<div id="app"≥
${content}
</div>
</body>
</html>`
reply(html)Options
<String> 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.
npm testwill run both server and browser testsnpm run test-browserandnpm run test-serverrun their respective testsnpm run tdd-serverwill run the server tests on every file change.npm run tdd-browserwill 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-tagswill work.brew install git
License
Artistic 2.0 © Joey Baker