Skip to content

Instantly share code, notes, and snippets.

@barbagrigia
Forked from theKashey/Title.js
Created December 27, 2018 21:54
Show Gist options
  • Save barbagrigia/7c86598bdae13fc475f962120686a551 to your computer and use it in GitHub Desktop.
Save barbagrigia/7c86598bdae13fc475f962120686a551 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