Created
March 5, 2017 06:00
-
-
Save AshikNesin/8741aa03a0a91d83e945580cb608eaef to your computer and use it in GitHub Desktop.
React Components
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
// 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