-
-
Save barbagrigia/7c86598bdae13fc475f962120686a551 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