react-helmet instead
Deprecated. Usereact-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-head
Usage
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 test
will run both server and browser tests -
npm run test-browser
andnpm 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