Skip to content

Instantly share code, notes, and snippets.

@theKashey
Created December 26, 2018 05:56
Show Gist options
  • Save theKashey/4e589eb667f6bc9edac5bdac1b729aec to your computer and use it in GitHub Desktop.
Save theKashey/4e589eb667f6bc9edac5bdac1b729aec to your computer and use it in GitHub Desktop.
Set document title from react node
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