react-page-parts
v0.5.0
Published
A way to extract other parts page, such as meta tags, from a React app.
Downloads
5
Readme
react-page-parts
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">
];
}
});