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

react-page-context

v0.0.5

Published

React Page Context allows to manage document's title, description and other meta tags, as well as <script> and <link> elements in SPA applications

Readme

React Page Context

NPM version NPM downloads Build Status Coverage Status Dependency Status Online Chat

A higher-order React component that allows to set document's title, description and other meta tags, as well as <link> and <script> tags from inside regular React components via context.page context variable.

See the changelog for past and future (planned) changes to the project  |  Join #react-starter-git on Gitter to stay up to date

How to Install

$ npm install react-page-context --save

Getting Started

  1. Import PageContext types from react-page-context npm module
  2. Add contextTypes static property to your React component that needs access to document.title and other <head> elements
  3. Use context.page function to manipulate document's <head> section

Here is an example:

components/HomePage.js

import React, { PropTypes } from 'react';

function HomePage(props, { page }) {
  page({
   title: 'My Home Page',
   description: 'Some page description',
   meta: [
     { name: 'twitter:card', content: 'summary' }
   ]
  });
  return (
    <div>
      <h1>Welcome!</h1>
      <p>This is my personal home page.</p>
    </div>
  );
}

HomePage.contextTypes = { page: PropTypes.func.isRequired };

export default HomePage;

main.js

import React from 'react';
import ReactDOM from 'react-dom';
import PageContext from 'react-page-context';
import HomePage from './components/HomePage';

ReactDOM.render(
  <PageContext>
    <HomePage />
  </PageContext>,
  document.getElementById('root')
);

It should yield the following HTML markup:

<html>
  <head>
    <title>My Home Page</title>
    <meta name="description" content="Some page description">
    <meta name="twitter:card" content="summary">
  </head>
  <body>
    ...
  </body>
</html>

Server-side Rendering Example

server.js

import express from 'express';
import ReactDOM from 'react-dom/server';
import PageContext from 'react-page-context';
import HomePage from './components/HomePage';

const app = express();

app.get('/', (req, res) => {
  let page;
  const body = ReactDOM.renderToString(
    <PageContext onChange={value => (page = value)}>
      <HomePage />
    </PageContext>
  );
  res.send(`
    <html>
      <head>
        <title>${page.title}</title>
        ${page.meta.map(meta => `<meta name="${meta.name}" content="${meta.content}">`)}
      </head>
      <body><div id="root">${body}</div></body>
    </html>
  `)
});

app.listen(3000);

Node: This is a simplified example. In a real-world app you would need to replace the ES6 template string above with a real template powered by Jade or EJS for security and performance considerations.

Contribute

♥ React Page Context and willing to contribute? Great! Here is a list of challenges you can help with:

  • Comment on the API design here
  • Add support of setting <link> and <script> elements via context.page(...)
  • Add support of setting HTML attributes such as lang="..."
  • Review and improve documentation to the project (README.md)
  • Review and improve the source code (createPage.js, PageContext.js)
  • Review and improve unit tests (PageContextSpec.js)
  • Suggest ways to improve performance of this component
  • Configure automated tests in real browsers via Travis and Sauce Labs or Browserstack
  • ...

Related Projects

Get in Touch

License

Copyright © 2016 Kriasoft, LLC. This source code is licensed under the MIT license found in the LICENSE.txt file. The documentation to the project is licensed under the CC BY-SA 4.0 license.


Made with ♥ by Konstantin Tarkus (@koistya) and contributors