Skip to content

Instantly share code, notes, and snippets.

@persocon
Created August 3, 2018 10:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save persocon/4a848736a2cbc6d1d38d6746746a46a2 to your computer and use it in GitHub Desktop.
Save persocon/4a848736a2cbc6d1d38d6746746a46a2 to your computer and use it in GitHub Desktop.
import React, {Component} from 'react';
import {withHelmet} from './helpers/withHelmet';
class BananaPage extends Component {
render() {
return (<p>Banana</p>)
}
}
const Page = withHelmet(BananaPage);
export {Page};
import React, { Fragment } from 'react';
import Helmet from 'react-helmet';
import PropTypes from 'prop-types';
function withHelmet(WrappedComponent) {
class WithHelmet extends React.Component {
helmet() {
return (
<Helmet>
<title>{this.props.title}</title>
<meta name="description" content={this.props.description} />
</Helmet>
);
}
render() {
return (
<Fragment>
{this.helmet()}
<WrappedComponent {...this.props} />
</Fragment>
);
}
}
WithHelmet.propTypes = {
title: PropTypes.string.isRequired,
description: PropTypes.string.isRequired,
};
return WithHelmet;
}
export {withHelmet};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment