Created
December 26, 2018 05:56
-
-
Save theKashey/4e589eb667f6bc9edac5bdac1b729aec to your computer and use it in GitHub Desktop.
Set document title from react node
This file contains hidden or 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
class Title extends React.PureComponent { | |
domNode = document.createElement('div'); | |
// ^ it's not added to the document | |
componentDidMount() { | |
this.componentDidUpdate(); | |
} | |
componentDidUpdate() { | |
document.title = this.domNode.textContent || ':('; | |
} | |
render() { | |
return ReactDOM.createPortal( | |
this.props.children, | |
this.domNode | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment