Created
August 3, 2018 10:10
-
-
Save persocon/4a848736a2cbc6d1d38d6746746a46a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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