Skip to content

Instantly share code, notes, and snippets.

@emilyruby
Last active January 4, 2018 17:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emilyruby/1ab2237bda8f14e783ef320a467f7d4a to your computer and use it in GitHub Desktop.
Save emilyruby/1ab2237bda8f14e783ef320a467f7d4a to your computer and use it in GitHub Desktop.
This is the example from the react-document-title readme. https://github.com/gaearon/react-document-title
function App() {
// Use "My Web App" if no child overrides this
return (
<DocumentTitle title='My Web App'>
<SomeRouter />
</DocumentTitle>
);
}
function HomePage() {
// Use "Home" while this component is mounted
return (
<DocumentTitle title='Home'>
<h1>Home, sweet home.</h1>
</DocumentTitle>
);
}
class NewArticlePage extends React.Component {
constructor(props) {
super(props);
this.state = { title: 'Untitled' };
}
render() {
// Update using value from state while this component is mounted
return (
<DocumentTitle title={this.state.title}>
<div>
<h1>New Article</h1>
<input
value={this.state.title}
onChange={(e) => this.setState({ title: e.target.value })}
/>
</div>
</DocumentTitle>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment