Skip to content

robcolburn/react-page-parts

Repository files navigation

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">
    ];
  }
});

About

A way to extract other parts page (META) from a React app

Resources

License

Stars

Watchers

Forks

Packages

No packages published