Skip to content

Instantly share code, notes, and snippets.

@Qquanwei
Created May 12, 2017 09:30
Show Gist options
  • Save Qquanwei/e96fc483715e39f5964a521c5d57270b to your computer and use it in GitHub Desktop.
Save Qquanwei/e96fc483715e39f5964a521c5d57270b to your computer and use it in GitHub Desktop.
react withTitle. change title when switch component
import React from 'react'
import createReactClass from 'create-react-class'
import cu from 'lodash/curry'
export default cu(function (title, Component) {
let oriTitle = document.title
return createReactClass({
componentWillMount () {
oriTitle = document.title
document.title = title
},
componentWillUnmount () {
document.title = oriTitle
},
render () {
return <Component {...this.props}/>
}
})
})
@Qquanwei
Copy link
Author

Qquanwei commented May 12, 2017

usag:

 withTitle('page A', Component)

or

withTitle('page B')(Component)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment