Skip to content

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

License

Notifications You must be signed in to change notification settings

joeybaker/react-document-head

Repository files navigation

Deprecated. Use react-helmet instead

react-document-head NPM version Dependency Status Build Status

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 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

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published