Skip to content

Instantly share code, notes, and snippets.

@AshikNesin
Created March 5, 2017 06:00
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 AshikNesin/8741aa03a0a91d83e945580cb608eaef to your computer and use it in GitHub Desktop.
Save AshikNesin/8741aa03a0a91d83e945580cb608eaef to your computer and use it in GitHub Desktop.
React Components
// https://github.com/gigobyte/react-document-title-decorator/blob/master/example/setTitle.jsx
import React from 'react'
const setTitle = (getTitle) => (WrappedComponent) => {
return class extends React.Component {
updateTitle = (props) => {
const title = getTitle(props)
if(title) {
document.title = title
}
}
componentDidMount() {
this.updateTitle(this.props)
}
componentWillReceiveProps(props) {
this.updateTitle(props)
}
render() {
return <WrappedComponent {...this.props} />
}
}
}
export default setTitle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment