Last active
January 30, 2016 06:59
-
-
Save ryanflorence/bbe292d4f5994500bd3b to your computer and use it in GitHub Desktop.
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
import React from 'react' | |
// need a getter and a hash of requestId:results or something | |
// to use in server rendering | |
let results = [] | |
function updateTitle() { | |
document.title = results[results.length - 1] | |
} | |
const Title = React.createClass({ | |
getInitialState() { | |
return { | |
index: results.push('') - 1 | |
} | |
}, | |
componentWillUnmount() { | |
results.pop() | |
}, | |
componentDidMount: updateTitle, | |
componentDidUpdate: updateTitle, | |
render() { | |
const { render } = this.props | |
results[this.state.index] = typeof render === 'function' | |
? render(results[this.state.index - 1] || '') | |
: render | |
return this.props.children || null | |
} | |
}) | |
export default Title |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Seems a bit gross to changing
document.title
within the component. What if you had aupdateTitle
function in context? That way,App
can decide what to do with it. Or even a nested component, such as a panel/modal/card, can have its own title hierarchy.