Skip to content

Instantly share code, notes, and snippets.

@persocon
Created Aug 3, 2018
Embed
What would you like to do?
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