Deprecated. Use react-helmet instead
Simple function to isomorphically set the <title> on the server and the client in a React workflow.
Table of Contents generated with DocToc
npm i -S react-document-head
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)
Set the title. On the client, this sets document.title
, on the server, it sets a global: React.documentHead
.
Tests are in tape.
npm test
will run both server and browser testsnpm run test-browser
andnpm run test-server
run their respective testsnpm 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.
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
- 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
Artistic 2.0 © Joey Baker