npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

reactjs-title

v1.1.4

Published

Nested document title management for React.js

Readme

This is a port from react-title-component

Reactjs Title

Nested document title management for React.

Installation

Using npm:

$ npm install reactjs-title

Then with a module bundler like webpack that supports either CommonJS or ES2015 modules, use as you would anything else:

// using an ES6 transpiler, like babel
import Title, { flushTitle } from 'reactjs-title'

// not using an ES6 transpiler
var ReactTitle = require('reactjs-title')
var Title = ReactTitle.default
var flushTitle = ReactTitle.flushTitle

The UMD build is also available on unpkg:

<script src="https://unpkg.com/reactjs-title/umd/ReactTitleComponent.min.js"></script>

You can find the library on window.ReactTitle.

Usage

<Title render="My Title"/>
// `document.title` will now be "My Title"

That's nice, but the idea is that you don't want just one component participating in the title of the document. As nested components come in and out of the UI, you often want to append (or prepend) to the current title.

// First instance of `Title`
<Title render="My Title"/>

// Lower in the view hierarchy, another `Title` is rendered.
// If you pass it a function you'll get the previous title's value,
// so you can append, prepend, or ignore it.
<Title render={previousTitle => `${previousTitle} - More Title`}/>

// the title, if both of those are rendered, will be:
// "My Title - More Title"

It ends up looking something like this:

import React from 'react'
import { render } from 'react-dom'
import Title from 'reactjs-title'

const App = React.createClass({

  render() {
    return (
      <div>
        <Title render="Awesome Website"/>
        <DeeperPage/>
        {/* ... */}
      </div>
    )
  }

})

const DeeperPage = React.createClass({

  getInitialState() {
    return { profile: null }
  },

  componentDidMount() {
    fetchProfile(profile => this.setState({ profile }))
  },

  render() {
    // because it's a component, it gets to participate in the render
    // lifecycle, updating the title as state changes...
    const { profile } = this.state
    const title = profile ? 'Loading...' : profile.fullName
    return (
      <div>
        <Title render={parentTitle => `More Stuff | ${title}`}/>
        {/* ... */}
      </div>
    )
  }

})

If you're using React Router, you probably want all of your route components to add something to the title.

Server Rendering

import { flushTitle } from 'reactjs-title'
import { renderToString } from 'react-dom/server'

const markup = renderToString(<App/>) // App has some Titles in it.
const title = flushTitle() // returns the title and gets ready for the
                           // next request

renderFullPageHoweverYouDoIt(markup, title)

Caveat

There is one caveat: You can't be removing titles from the middle of the chain. In other words, make sure that if your component renders a Title, it always renders a Title.

// GOOD
render() {
  return (
    <div>
      <Title render={prev => `${prev} | stuff`}/>
    </div>
  )
}

// BAD
render() {
  return (
    <div>
      {!this.state.screwUpTheTitleLib && (
        <Title render={prev => `${prev} | stuff`}/>
      )}
    </div>
  )
}

This could cause a title in the middle of the "title chain" to be removed and then screw everything else up, the code makes assumptions based on the order they get rendered.

This could be worked around, but it seems like a strange use-case that would complicate the code a bit.

Enjoy!