react-page-parts

0.5.0 • Public • Published

react-page-parts

npm package build status dependency status

A way to extract other parts page, such as meta tags, from a React app.

When building a React app with data pumping through, you may discover that you want to extract other pieces of the page, such as: page title, description, meta open graph tags, etc…

Integration

Wrapping around where you call React's render function, you'll reset the component list and then extract component trees.

var PageParts = require('react-page-parts');
PageParts.reset();
var app = React.renderToString(React.createElement(App));
var meta = React.renderToStaticMarkup(React.createElement('head', null, React.addons.createFragment(
  PageParts.get('meta')
)));

In your component:

var React = require('react');
var PageParts = require('react-page-parts');
 
var CoffeeShop = React.createClass({
  componentWillMount: function () {
    PageParts.push(this);
  },
  meta: function () {
    return [
      <title>Coffee Shop</title>,
      <meta name="description" content="Coffe is delish">
    ];
  }
});

Package Sidebar

Install

npm i react-page-parts

Weekly Downloads

8

Version

0.5.0

License

MIT

Last publish

Collaborators

  • robcolburn