Last active
January 4, 2018 17:57
-
-
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
This file contains 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
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